import { z } from "zod";

const nullableText50 = z.string().trim().max(50).nullable().optional();
const nullableText150 = z.string().trim().max(150).nullable().optional();
const nullableText255 = z.string().trim().max(255).nullable().optional();
const nullableText = z.string().trim().nullable().optional();

const nullableNumber = z.number().nullable().optional();
const nullableBoolean = z.boolean().nullable().optional();
const activeBoolean = z.boolean().optional();

/* TYPES ABSENCE */

export const typeAbsenceFormSchema = z
  .object({
    typeabsence: nullableText150,
    libabsence: nullableText255,
    actif: activeBoolean,
  })
  .strict();

export const typeAbsenceCreateSchema = typeAbsenceFormSchema.extend({
  typeabsence: z.string().trim().max(150),
});

export const typeAbsenceUpdateSchema = typeAbsenceFormSchema.partial();

export type TypeAbsenceCreateInput = z.infer<typeof typeAbsenceCreateSchema>;
export type TypeAbsenceUpdateInput = z.infer<typeof typeAbsenceUpdateSchema>;

/* TYPES AVENANTS */

export const typeAvenantFormSchema = z
  .object({
    avenantsid: nullableNumber,
    avenantstypes: nullableText255,
    actif: activeBoolean,
  })
  .strict();

export const typeAvenantCreateSchema = typeAvenantFormSchema.extend({
  avenantstypes: z.string().trim().max(255),
});

export const typeAvenantUpdateSchema = typeAvenantFormSchema.partial();

export type TypeAvenantCreateInput = z.infer<typeof typeAvenantCreateSchema>;
export type TypeAvenantUpdateInput = z.infer<typeof typeAvenantUpdateSchema>;

/* TYPES DIPLOME */

export const typeDiplomeFormSchema = z
  .object({
    diplome: nullableText255,
    dureeanneesvalidite: nullableNumber,
    actif: activeBoolean,
  })
  .strict();

export const typeDiplomeCreateSchema = typeDiplomeFormSchema.extend({
  diplome: z.string().trim().max(255),
});

export const typeDiplomeUpdateSchema = typeDiplomeFormSchema.partial();

export type TypeDiplomeCreateInput = z.infer<typeof typeDiplomeCreateSchema>;
export type TypeDiplomeUpdateInput = z.infer<typeof typeDiplomeUpdateSchema>;

/* TYPES CONTRAT SALARIE */

export const typeContratFormSchema = z
  .object({
    tcs: nullableText150,
    chemin: nullableText255,
    regroupement: nullableText150,
    faitpartie_e2e: nullableBoolean,
    actif: activeBoolean,
  })
  .strict();

export const typeContratCreateSchema = typeContratFormSchema.extend({
  tcs: z.string().trim().max(150),
});

export const typeContratUpdateSchema = typeContratFormSchema.partial();

export type TypeContratCreateInput = z.infer<typeof typeContratCreateSchema>;
export type TypeContratUpdateInput = z.infer<typeof typeContratUpdateSchema>;

/* TYPES CS */

export const typeCsFormSchema = z
  .object({
    typecs: nullableText150,
    report3mois: nullableBoolean,
    typeao: nullableText150,
    actif: activeBoolean,
  })
  .strict();

export const typeCsCreateSchema = typeCsFormSchema.extend({
  typecs: z.string().trim().max(150),
});

export const typeCsUpdateSchema = typeCsFormSchema.partial();

export type TypeCsCreateInput = z.infer<typeof typeCsCreateSchema>;
export type TypeCsUpdateInput = z.infer<typeof typeCsUpdateSchema>;

/* CLASSIFICATIONS */

export const classificationFormSchema = z
  .object({
    id_classification: nullableNumber,
    classification: nullableText150,
    niveau: nullableText50,
    echelon: nullableText50,
    coefficient: nullableNumber,
    actif: activeBoolean,
    etablissement: nullableText150,
  })
  .strict();

export const classificationCreateSchema = classificationFormSchema.extend({
  classification: z.string().trim().max(150),
});

export const classificationUpdateSchema = classificationFormSchema.partial();

export type classificationCreateInput = z.infer<
  typeof classificationCreateSchema
>;
export type classificationUpdateInput = z.infer<
  typeof classificationUpdateSchema
>;

/* ETABLISSEMENTS */

export const etablissementFormSchema = z
  .object({
    etb: nullableText150,
    entreprise: nullableText255,
    directeur: nullableText255,
    adressesiege: nullableText255,
    adresseetb: nullableText255,
    actif: activeBoolean,
  })
  .strict();

export const etablissementCreateSchema = etablissementFormSchema.extend({
  etb: z.string().trim().max(150),
});

export const etablissementUpdateSchema = etablissementFormSchema.partial();

export type etablissementCreateInput = z.infer<
  typeof etablissementCreateSchema
>;
export type etablissementUpdateInput = z.infer<
  typeof etablissementUpdateSchema
>;

/* POSTES */

export const posteFormSchema = z
  .object({
    etablissement: nullableText150,
    pos: nullableText150,
    intitule: z.string().trim().max(150).optional(),
    code_poste: nullableText50,
    description: nullableText,
    actif: activeBoolean,
  })
  .strict();

export const posteCreateSchema = posteFormSchema.extend({
  intitule: z.string().trim().max(150),
});

export const posteUpdateSchema = posteFormSchema.partial();

export type posteCreateInput = z.infer<typeof posteCreateSchema>;
export type posteUpdateInput = z.infer<typeof posteUpdateSchema>;

/* SECTEURS */

export const secteurFormSchema = z
  .object({
    tse: nullableText255,
    actif: activeBoolean,
  })
  .strict();

export const secteurCreateSchema = secteurFormSchema.extend({
  tse: z.string().trim().max(255),
});

export const secteurUpdateSchema = secteurFormSchema.partial();

export type secteurCreateInput = z.infer<typeof secteurCreateSchema>;
export type secteurUpdateInput = z.infer<typeof secteurUpdateSchema>;

/* CPAM */

export const cpamFormSchema = z
  .object({
    localite: nullableText255,
    adresse: nullableText255,
    actif: activeBoolean,
  })
  .strict();

export const cpamCreateSchema = cpamFormSchema.extend({
  localite: z.string().trim().max(255),
});

export type cpamCreateInput = z.infer<typeof cpamCreateSchema>;
export type cpamUpdateInput = z.infer<typeof cpamFormSchema>;

/* MOTIFS DEROGATION MUTUELLE */

export const motifsMFormSchema = z
  .object({
    motifsderogation: nullableText255,
    actif: activeBoolean,
  })
  .strict();

export const motifsMCreateSchema = motifsMFormSchema.extend({
  motifsderogation: z.string().trim().max(255),
});

export type motifsMCreateInput = z.infer<typeof motifsMCreateSchema>;
export type motifsMUpdateInput = z.infer<typeof motifsMFormSchema>;