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 TEXT
    , location_name TEXT
    , acquired_from TEXT
    , 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 TEXT
    , grading_company_name TEXT
    , grading_score TEXT
    , subgrades TEXT
    , misprint_errors TEXT
    , miscut_errors TEXT
    , playability TEXT
    , 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 TEXT
    , trading_status_name TEXT
    , 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 TEXT
    , 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
    , front_name TEXT NOT NULL
    , rear_name TEXT
    , 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)
);
