const fields = foundry.data.fields;

export function statField(initialValue = 0, label = "", derivee = false) {
  return new fields.SchemaField({
    type: new fields.StringField({ initial: "number" }),
    value: new fields.NumberField({ initial: initialValue, integer: true }),
    label: new fields.StringField({ initial: label }),
    xp: new fields.NumberField({ initial: 0, integer: true }),
    derivee: new fields.BooleanField({ initial: derivee }),
  });
}

export function santeField(initialValue = 0, initialMax = 0, label = "", derivee = false) {
  return new fields.SchemaField({
    type: new fields.StringField({ initial: "number" }),
    value: new fields.NumberField({ initial: initialValue, integer: true }),
    max: new fields.NumberField({ initial: initialMax, integer: true }),
    label: new fields.StringField({ initial: label }),
    derivee: new fields.BooleanField({ initial: derivee }),
  });
}

export function attributField(initialValue = 0, label = "", derivee = false, isString = false) {
  if (isString) {
    return new fields.SchemaField({
      type: new fields.StringField({ initial: "string" }),
      value: new fields.StringField({ initial: String(initialValue) }),
      label: new fields.StringField({ initial: label }),
      derivee: new fields.BooleanField({ initial: derivee }),
    });
  }
  return new fields.SchemaField({
    type: new fields.StringField({ initial: "number" }),
    value: new fields.NumberField({ initial: initialValue, integer: false }),
    label: new fields.StringField({ initial: label }),
    derivee: new fields.BooleanField({ initial: derivee }),
  });
}

export function compteurField(initialValue = 0, label = "", isInput = false) {
  return new fields.SchemaField({
    value: new fields.NumberField({ initial: initialValue, integer: true }),
    label: new fields.StringField({ initial: label }),
    ...(isInput ? { isInput: new fields.BooleanField({ initial: true }) } : {}),
  });
}

export function compteurMaxField(initialValue = 0, initialMax = 0, label = "") {
  return new fields.SchemaField({
    value: new fields.NumberField({ initial: initialValue, integer: true }),
    max: new fields.NumberField({ initial: initialMax, integer: true }),
    label: new fields.StringField({ initial: label }),
    isInput: new fields.BooleanField({ initial: true }),
  });
}
