CREATE TABLE tcg.public.TCG_MTG_Inventory (
	  inventory_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY
    , card_id INT NOT NULL
    , CONSTRAINT FK_TCG_MTG_Inventory_card_id
        FOREIGN KEY (card_id)
        REFERENCES tcg.public.TCG_MTG_Card(card_id)
    , finish_id INT NOT NULL
    , CONSTRAINT FK_TCG_MTG_Inventory_finish_id
        FOREIGN KEY (finish_id)
        REFERENCES tcg.public.TCG_MTG_Finish(finish_id)
    , condition_id INT NOT NULL
    , CONSTRAINT FK_TCG_MTG_Inventory_condition_id
        FOREIGN KEY (condition_id)
        REFERENCES tcg.public.TCG_Condition(condition_id)
    , sleeve_colour_name VARCHAR(250)
    , location_name VARCHAR(250)
    , acquired_from VARCHAR(500)
    , acquired_on TIMESTAMP
    , cost_gbp DECIMAL(6, 2) NOT NULL
    , sale_price_gbp DECIMAL(6, 2)
    , is_sold BOOLEAN NOT NULL DEFAULT FALSE
    , is_destroyed BOOLEAN NOT NULL DEFAULT FALSE
    , notes TEXT
    , alterations_customisations VARCHAR(250)
    , grading_company_name VARCHAR(250)
    , grading_score VARCHAR(250)
    , subgrades VARCHAR(250)
    , misprint_errors VARCHAR(250)
    , miscut_errors VARCHAR(250)
    , playability VARCHAR(250)
    , owner_user_id INT NOT NULL
    , CONSTRAINT FK_TCG_MTG_Inventory_owner_user_id
        FOREIGN KEY (owner_user_id)
        REFERENCES tcg.public.TCG_User(user_id)
    , ownership_status_name VARCHAR(250)
    , trading_status_name VARCHAR(250)
    , loaned_to_user_id INT
    , CONSTRAINT FK_TCG_MTG_Inventory_loaned_to_user_id
        FOREIGN KEY (loaned_to_user_id)
        REFERENCES tcg.public.TCG_User(user_id)
    , loan_start_on TIMESTAMP
    , loan_end_on TIMESTAMP
    , provenance TEXT
    , signed_by_names TEXT
    , signature_condition_name VARCHAR(250)
    , token_rear_side_card_id INT
    , CONSTRAINT FK_TCG_MTG_Inventory_token_rear_side_card_id
        FOREIGN KEY (token_rear_side_card_id)
        REFERENCES tcg.public.TCG_MTG_Card(card_id)
    , display_order INT NOT NULL
    , active BOOLEAN NOT NULL DEFAULT TRUE
	, created_on TIMESTAMP NOT NULL
	, created_by_user_id INT NOT NULL
    , CONSTRAINT FK_TCG_MTG_Inventory_created_by_user_id
        FOREIGN KEY (created_by_user_id)
        REFERENCES tcg.public.TCG_User(user_id)
	, updated_last_on TIMESTAMP NOT NULL
	, updated_last_by_user_id INT NOT NULL
    , CONSTRAINT FK_TCG_MTG_Inventory_updated_last_by_user_id
        FOREIGN KEY (updated_last_by_user_id)
        REFERENCES tcg.public.TCG_User(user_id)
    , change_set_id INT NOT NULL
    , CONSTRAINT FK_TCG_MTG_Inventory_change_set_id
		FOREIGN KEY (change_set_id)
        REFERENCES tcg.public.TCG_Change_Set(change_set_id)
);
