const fields = foundry.data.fields;

export function createCharacteristicField(show = true, showMax = false) {
    return new fields.SchemaField({
        value: new fields.NumberField({ required: true, initial: 0, min: 0, integer: true }),
        max: new fields.NumberField({ required: false, initial: 0, min: 0, integer: true }),
        dm: new fields.NumberField({ required: false, initial: 0, integer: true }),
        show: new fields.BooleanField({ required: false, initial: show }),
        showMax: new fields.BooleanField({ required: false, initial: showMax })
    });
}

export class ItemBaseData extends foundry.abstract.TypeDataModel {
    static defineSchema() {
        return {
            description: new fields.StringField({ required: false, blank: true, trim: true, nullable: true }),
            subType: new fields.StringField({ required: false, blank: false, nullable: true })
        };
    }
}

export class PhysicalItemData extends ItemBaseData {
    static defineSchema() {
        const schema = super.defineSchema();
        schema.quantity = new fields.NumberField({ required: true, initial: 1, min: 0, integer: true });
        schema.weight = new fields.NumberField({ required: true, initial: 0, min: 0, integer: false });
        schema.weightless = new fields.BooleanField({ required: false, initial: false });
        schema.cost = new fields.NumberField({ required: true, initial: 0, min: 0, integer: true });
        schema.tl = new fields.StringField({ required: true, blank: false, initial: "TL12" });
        schema.container = new fields.SchemaField({
            id: new fields.StringField({ required: false, blank: true })
        });
        schema.roll = new fields.SchemaField({
            characteristic: new fields.StringField({ required: false, blank: true, trim: true }),
            skill: new fields.StringField({ required: false, blank: true, trim: true }),
            difficulty: new fields.StringField({ required: false, blank: true, trim: true })
        });
        schema.trash = new fields.BooleanField({ required: false, initial: false });
        return schema;
    }
}
