import { z } from "zod";
import { bedSchema } from "./bed.schema";
import { occupanciesSchema } from "./occupancy.schema";
import { otpsSchema } from "./otp.schema";
import { roomsSchema } from "./room.schema";
import { ledgerSchema } from "./ledger.schema";

export const tenantsSchema = z.object({
  id: z.number(),
  gId: z.string(),
  tId: z.string(),
  name: z
    .string()
    .min(3, "Name should be atleast 3 characters")
    .max(150, "Name shouldn't be more than 150 characters"),
  mobile: z
    .string()
    .min(10, "Mobile number should be 10-digit only.")
    .max(10, "Mobile number should be 10-digit only."),
  device: z.number(),
  gender: z.number(),
  bloodGroup: z.string(),
  aadharNumber: z.string(),
  occupation: z.string(),
  fatherName: z.string(),
  dob: z.string(),
  lastRemindedOn: z.string(),
  email: z.string(),
  alternateMobile: z.string(),
  address: z.string(),
  regId: z.string(),
  status: z.number(),
  kycStatus: z.number(),
  eqaroStatus: z.number(),
  eqaroUserId: z.string(),
  institutionName: z.string(),
  institutionEmail: z.string(),
  courseEndMonth: z.string(),
  courseEndYear: z.number(),
  title: z.string(),
  fatherMobile: z.string(),
  motherName: z.string(),
  motherMobile: z.string(),
  verificationId: z.string(),
  referenceId: z.number(),
  lastLogin: z.string().datetime(),
  createdAt: z.string().datetime(),
  updatedAt: z.string().datetime(),
});

type tenantsTypes = z.infer<typeof tenantsSchema>;

export const loginSchema = z.object({
  mobile: tenantsSchema.shape.mobile,
  device: tenantsSchema.shape.device.optional(),
});
export const otpVerificationSchema = z.object({
  otp: otpsSchema.shape.otp,
  mobile: tenantsSchema.shape.mobile,
});
export const onBoardingSchema = z.object({
  propGId: z.string(),
  name: tenantsSchema.shape.name,
});

export const addBasicTenantSchema = z.object({
  bedId: bedSchema.shape.id,
  propId: z.number(),
  roomId: roomsSchema.shape.id,
  fullName: tenantsSchema.shape.name,
  mobile: tenantsSchema.shape.mobile,
  gender: tenantsSchema.shape.gender,
  occupation: tenantsSchema.shape.occupation,
  alternateMobile: tenantsSchema.shape.alternateMobile.optional(),
  allBedsOccupied: z.boolean(),
});

export const addTenantAgreementSchema = z.object({
  monthlyRent: occupanciesSchema.shape.rent,
  securityDeposit: occupanciesSchema.shape.security,
  agreementStartDate: occupanciesSchema.shape.agreementStartDate,
  rentalCycle: occupanciesSchema.shape.rentalCycle,
  agreementPeriod: occupanciesSchema.shape.agreementPeriod,
  noticePeriod: occupanciesSchema.shape.noticePeriod,
  lockInPeriod: occupanciesSchema.shape.lockInPeriod,
  moveInDate: occupanciesSchema.shape.moveInDate,
  tenantId: tenantsSchema.shape.id,
  propId: z.number(),
  roomId: roomsSchema.shape.id,
  electricityReading: occupanciesSchema.shape.electricityReading,
});

export const addTenantAgreementSchemaX = z.object({
  monthlyRent: occupanciesSchema.shape.rent,
  securityDeposit: occupanciesSchema.shape.security,
  agreementStartDate: occupanciesSchema.shape.agreementStartDate,
  rentalCycle: occupanciesSchema.shape.rentalCycle,
  rentalType: occupanciesSchema.shape.rentalType,
  agreementPeriod: occupanciesSchema.shape.agreementPeriod,
  noticePeriod: occupanciesSchema.shape.noticePeriod,
  lockInPeriod: occupanciesSchema.shape.lockInPeriod,
  moveInDate: occupanciesSchema.shape.moveInDate,
  tenantId: tenantsSchema.shape.id,
  propId: z.number(),
  roomId: roomsSchema.shape.id,
  electricityReading: occupanciesSchema.shape.electricityReading,
});

export const addInitialSettlementSchema = z.object({
  tenantId: tenantsSchema.shape.id,
  ledgerReferenceId: ledgerSchema.shape.referenceId,
  type:z.number(),
  amount:z.number(),
})

export const addIDNumberSchema = z.object({
  IdNumber: z.string(),
});

export const verifyIDNumberSchema = z.object({
  otp: z.string(),
  docId: z.number(),
  requestId: z.string(),
});

export const addPersonalInfoSchema = z.object({
  name: tenantsSchema.shape.name,
  fatherName: tenantsSchema.shape.fatherName,
  dob: tenantsSchema.shape.dob,
  gender: tenantsSchema.shape.gender,
  occupation: tenantsSchema.shape.occupation.optional(),
  email: tenantsSchema.shape.email.optional(),
  alternateMobile: tenantsSchema.shape.alternateMobile.optional(),
  address: tenantsSchema.shape.address,
});

export const payOfflineSchema = z.object({
  dueIds: z.array(z.number().gt(0)),
  userType: z.number().gt(0),
  userId: z.number().gt(0),
});

export const payOfflineOTPVerifySchema = z.object({
  dueIds: z.array(z.number().gt(0)),
  userType: z.number().gt(0),
  userId: z.number().gt(0),
  otp: z.string(),
});

export const moveOutRequestSchema = z.object({
  moveOutDate: z.string().date(),
  reason: z.string(),
});

export const markAsPaidByClientSchema = z.object({
  collectionDate: z.string().datetime(),
  id: z.number().gt(0),
  mode: z.number().gt(0),
  amount: z.number().gt(0),
});

export const reserveInitiateSchema = z.object({
  bedId: bedSchema.shape.id,
  propId: z.number(),
  roomId: roomsSchema.shape.id,
  fullName: tenantsSchema.shape.name,
  mobile: tenantsSchema.shape.mobile,
  gender: tenantsSchema.shape.gender,
  occupation: tenantsSchema.shape.occupation,
  allBedsOccupied: z.boolean(),
});

export const reserveSchema = z.object({
  monthlyRent: occupanciesSchema.shape.rent,
  securityDeposit: occupanciesSchema.shape.security,
  agreementStartDate: occupanciesSchema.shape.agreementStartDate,
  rentalCycle: occupanciesSchema.shape.rentalCycle,
  agreementPeriod: occupanciesSchema.shape.agreementPeriod,
  noticePeriod: occupanciesSchema.shape.noticePeriod,
  lockInPeriod: occupanciesSchema.shape.lockInPeriod,
  moveInDate: occupanciesSchema.shape.moveInDate,
  tenantId: tenantsSchema.shape.id,
  propId: z.number(),
  roomId: roomsSchema.shape.id,
});

export const cancelReservationSchema = z.object({
  tenantId: z.number().gt(0),
});

export const cancelMoveOutRequestSchema = z.object({
  requestId: z.number().gt(0),
});

export const rejectMoveOutRequestSchema = z.object({
  requestId: z.number().gt(0),
});

export const updateRegIdSchema = z.object({
  regId: z.string(),
});

export const moveInInspectionSchema = z.object({
  desc: z.string(),
  //typeId: z.number(),
});

export const editProfileSchema = z.object({
  alternateMobile: tenantsSchema.shape.alternateMobile,
  occupation: z.string(),
});

export const addPanSchema = z.object({
  IdNumber: z.string(),
  IdName: z.string(),
});

export const addOccupationDetailsSchema = z.object({
  institutionName: tenantsSchema.shape.institutionName,
  title: tenantsSchema.shape.title,
  institutionEmail: tenantsSchema.shape.institutionEmail.optional(),
});

export const addGuardianDetailsSchema = z.object({
  fatherMobile: tenantsSchema.shape.fatherMobile.optional(),
  motherName: tenantsSchema.shape.motherName.optional(),
  motherMobile: tenantsSchema.shape.motherMobile.optional(),
});

export default tenantsTypes;
