import { Router } from "express";
import tenant from "../controllers/tenant.controller";
import authorize from "../middlewares/authorization.middleware";
import validateData from "../middlewares/validation.middleware";
import {
  addBasicTenantSchema,
  addIDNumberSchema,
  addPersonalInfoSchema,
  addTenantAgreementSchema,
  cancelMoveOutRequestSchema,
  cancelReservationSchema,
  loginSchema,
  markAsPaidByClientSchema,
  moveOutRequestSchema,
  onBoardingSchema,
  otpVerificationSchema,
  payOfflineOTPVerifySchema,
  payOfflineSchema,
  reserveInitiateSchema,
  reserveSchema,
  verifyIDNumberSchema,
  rejectMoveOutRequestSchema,
  updateRegIdSchema,
  moveInInspectionSchema,
  editProfileSchema,
  addPanSchema,
  addOccupationDetailsSchema,
  addGuardianDetailsSchema,
  addInitialSettlementSchema,
} from "../schemas/tenant.schema";
import {
  multerArrayFn,
  multerSingleFn,
} from "../middlewares/multer.middleware";
import { addTenantGuardianSchema } from "../schemas/tenantGuardian.schema";
import { AddTenantGuestSchema } from "../schemas/tenantGuests.schema";
import { AddNoteSchema } from "../schemas/tenantNotes.schema";

const router = Router();

router.post("/login", validateData(loginSchema), tenant.Login);
router.post(
  "/otp/verify",
  validateData(otpVerificationSchema),
  tenant.OTPVerify
);

router.post(
  "/login/with/property",
  tenant.LoginWithProperty
);

router.get("/checkin/details/:encryptedId", tenant.GetWebCheckinDetails);
router.get("/web/checkout/:encryptedId", tenant.WebPaymentCheckout);
router.get("/web/payment/:encryptedId/:dueId", tenant.WebPaymentCheckoutX);

// PROTECTED ROUTES
router.post(
  "/onboarding",
  authorize,
  validateData(onBoardingSchema),
  tenant.OnBoarding
);

router.get("/dashboard", authorize, tenant.Dashboard);
router.get("/details", authorize, tenant.GetDetails);

router.post(
  "/add/basic",
  authorize,
  validateData(addBasicTenantSchema),
  tenant.AddBasicByClient
);

router.post(
  "/add/agreement",
  authorize,
  validateData(addTenantAgreementSchema),
  tenant.AddAgreementByClient
);

router.post(
  "/add/agreement/new",
  authorize,
  validateData(addTenantAgreementSchema),
  tenant.AddAgreementByClientX
);

router.post(
  "/add/agreement/short/stay",
  authorize,
  tenant.AddAgreementByClientShortStay
);

router.post(
  "/add/agreement/short/stay/new",
  authorize,
  tenant.AddAgreementByClientShortStayX
);

router.post("/add/initial/settlement",
  authorize,
  validateData(addInitialSettlementSchema),
  tenant.AddInitialSettlementByClient
); 

router.get("/list", authorize, tenant.ListForClient);
router.get("/list/new", authorize, tenant.ListForClientX);
router.get("/list/web", authorize, tenant.ListForWeb);

router.get("/details/:tenantId", authorize, tenant.GetDetailsByClient);
router.get("/details/web/:tenantId", authorize, tenant.GetDetailForWeb);

router.post(
  "/kyc/add/id",
  authorize,
  validateData(addIDNumberSchema),
  tenant.AddIDNumber
);

router.post(
  "/kyc/add/pan",
  authorize,
  validateData(addPanSchema),
  tenant.AddPanNumber
);

router.post(
  "/kyc/upload/id",
  authorize,
  (req, res, next) => multerArrayFn(req, res, next, 2),
  tenant.UploadID
);

//Currently This is being used for Atharva Hostel
router.post(
  "/kyc/upload/documents",
  authorize,
  (req, res, next) => multerArrayFn(req, res, next, 2),
  tenant.UploadKycDocument
);

router.post(
  "/kyc/verify/id",
  authorize,
  validateData(verifyIDNumberSchema),
  tenant.VerifyIDNumber
);

router.post("/kyc/upload/selfi", authorize, multerSingleFn, tenant.UploadSelfi);

router.get("/agreement-terms", authorize, tenant.GetRentAgreementTerms);
router.get("/payment/collectors", authorize, tenant.PaymentCollectorsListing);
router.get("/profile", authorize, tenant.ViewProfile);
router.get("/authentication", authorize, tenant.AuthenticationDetails);
router.get("/move-in/types", authorize, tenant.MoveInInspectionTypeList);
router.get(
  "/move-in/details/:typeId",
  authorize,
  tenant.GetMoveInInspectionImages
);

router.post(
  "/profile/edit",
  authorize,
  validateData(editProfileSchema),
  tenant.EditProfile
);

router.post(
  "/profile/occupation/update",
  authorize,
  multerSingleFn,
  validateData(addOccupationDetailsSchema),
  tenant.AddOccupationDetails
);

router.post(
  "/profile/guardian/update",
  authorize,
  validateData(addGuardianDetailsSchema),
  tenant.AddGuardianDetails
);

router.post(
  "/rent-agreement/create",
  authorize,
  multerSingleFn,
  tenant.CreateRentAgreement
);

router.post(
  "/rent-agreement/createWithParent",
  authorize,
  (req, res, next) => multerArrayFn(req, res, next, 2),
  tenant.CreateRentAgreementWithParentSignature
);

router.post(
  "/rent-agreement/createMultipleSig",
  authorize,
  (req, res, next) => multerArrayFn(req, res, next, 2),
  tenant.CreateRentAgreementWithMultiSignature
);

router.post(
  "/personal-info/add",
  authorize,
  validateData(addPersonalInfoSchema),
  tenant.AddPersonalInfo
);

router.post(
  "/pay/offline",
  authorize,
  validateData(payOfflineSchema),
  tenant.PayOffline
);

router.post(
  "/pay/offline/otp/verify",
  authorize,
  validateData(payOfflineOTPVerifySchema),
  tenant.PayOfflineOTPVerify
);

router.post(
  "/request/move-out",
  authorize,
  validateData(moveOutRequestSchema),
  tenant.MoveOutRequest
);

router.delete("/delete", authorize, tenant.DeleteAccount);

router.post(
  "/dues/all/paid",
  authorize,
  validateData(markAsPaidByClientSchema),
  tenant.MarkAsPaidByClient
);

router.post(
  "/reserve/initiate",
  authorize,
  validateData(reserveInitiateSchema),
  tenant.InitiateReserveTenant
);

router.post(
  "/reserve/new",
  authorize,
  validateData(reserveSchema),
  tenant.ReserveTenantX
);

router.post(
  "/reserve/multiple/initiate",
  authorize,
  validateData(reserveInitiateSchema),
  tenant.InitiateReserveMultipleTenant
);

router.post(
  "/reserve/multiple",
  authorize,
  validateData(reserveSchema),
  tenant.ReserveMultipleTenant
);

router.post(
  "/reserve",
  authorize,
  validateData(reserveSchema),
  tenant.ReserveTenant
);

router.post(
  "/reserve/cancel",
  authorize,
  validateData(cancelReservationSchema),
  tenant.CancelReservation
);

router.get("/details/bed/:bedId", authorize, tenant.GetTenantByBed);
router.get("/details/client/:pan", authorize, tenant.GetOwnerByPAN);

router.get(
  "/request/status/:requestId",
  authorize,
  tenant.MoveOutRequestStatus
);

router.post(
  "/request/cancel",
  authorize,
  validateData(cancelMoveOutRequestSchema),
  tenant.CancelMoveOutRequest
);

router.post(
  "/request/reject",
  authorize,
  validateData(rejectMoveOutRequestSchema),
  tenant.RejectMoveOutRequest
);

router.post(
  "/regid/update",
  authorize,
  validateData(updateRegIdSchema),
  tenant.UpdateRegId
);

router.post(
  "/move-in",
  authorize,
  (req, res, next) => multerArrayFn(req, res, next, 6),
  validateData(moveInInspectionSchema),
  tenant.MoveInInspection
);

router.get(
  "/list/dropdown", 
  authorize, 
  tenant.GetList
);

// Using in web and app both
router.get(
  "/search/web", 
  authorize, 
  tenant.Search
);

router.post(
  "/update/rent/details/web",
  authorize,
  tenant.UpdateRentDetailsForWeb
);

router.post(
  "/update/personal/details",
  authorize,
  tenant.UpdatePersonalDetails
);

router.post(
  "/update/occupation/details",
  authorize,
  tenant.UpdateOccupationDetails
);

router.post(
  "/update/guardian/details",
  authorize,
  validateData(addTenantGuardianSchema),
  tenant.UpdateGuardianDetails
);

router.get(
  "/web/agreement-expiring",
  authorize,
  tenant.GetExpiringAgreementsForWeb
);

router.post(
  "/mark/attendance",
  authorize,
  tenant.MarkAttendance,
);
router.get(
  "/list/attendance/property",
  authorize,
  tenant.ListAttendanceForProperty,
);
router.get(
  "/list/attendance/property/web",
  authorize,
  tenant.ListAttendanceForPropertyForWeb,
);
router.get(
  "/list/attendance/stats",
  authorize,
  tenant.ListAttendanceStatsGroupByProp,
);
router.get(
  "/list/attendance/stats/web",
  authorize,
  tenant.ListAttendanceStatsGroupByPropForWeb,
);
router.get(
  "/list/attendance/:tenantId",
  authorize,
  tenant.ListParticularAttendance,
);

router.get(
  "/download/profile/:tenantId",
  authorize,
  tenant.DownloadTenantProfile
);

router.post(
  "/send/reminder/ekyc",
  authorize,
  tenant.SendEKYCReminder
);

router.post(
  "/send/onboarding/reminder",
  authorize,
  tenant.SendOnboardingReminder
);

router.post(
  "/change/rental/cycle",
  authorize,
  tenant.ChangeRentalCycle
);

router.post(
  "/kyc/digilocker/initiate",
  authorize,
  tenant.InitiateAadharVerifyDigiLocker
);

router.get(
  "/kyc/digilocker/verify",
  tenant.VerifyDigilockerRequest,
);

router.get(
  "/rent-agreement/re-generate",
  tenant.ManuallyCreateRentAgreement
);

router.get(
  "/rent-agreement/re-generate-mergepdf",
  tenant.ManuallyCreateRentAgreementMergePdf
);

router.get(
  "/kyc/digilocker/client/verify",
  tenant.VerifyDigilockerRequestViaClient,
);

router.post(
  "/book/again",
  authorize,
  tenant.BookAgain,
);

router.post(
  "/request/refund",
  authorize,
  multerSingleFn,
  tenant.RefundRequest,
);

router.post(
  "/request/refund/reject",
  authorize,
  tenant.RejectRefundRequest,
);

router.post(
  "/toggle/food",
  authorize,
  tenant.ToggleFood,
);

router.post(
  "/toggle/transportation",
  authorize,
  tenant.ToggleBus,
);

router.get(
  "/list/renewed/agreements",
  authorize,
  tenant.ListRenewedRentAgreements,
);

router.get(
  "/get/final/breakdown",
  authorize,
  tenant.GetFullAndFinalBreakdown,
);

router.post(
  "/manually/movein",
  authorize,
  tenant.ManuallyMoveIn,
);

router.post(
  "/request/guest",
  authorize,
  validateData(AddTenantGuestSchema),
  tenant.GuestRequest
);
router.get("/request/guest/list", authorize, tenant.ListGuestRequestForTenant);

router.post(
  "/request/movement", authorize, tenant.AddMovementRequest
);

router.get("/request/movement/list", authorize, tenant.ListMovementRequestForTenant);
router.get("/request/movement/list-for-client", authorize, tenant.ListMovementRequestForClient);
router.get("/send/otp/parent", authorize, tenant.SendOTPToParents);
router.post("/verify/parent/otp", authorize, tenant.ParentOTPVerify);



router.post(
  "/add/note",
  authorize,
  validateData(AddNoteSchema),
  tenant.AddTenantNotes
);

router.get("/notes/list", authorize, tenant.listNotes);
router.post("/notes/delete", authorize, tenant.DeleteNote);

router.post(
  "/sos/send", authorize, tenant.SendSOSAlert
);

router.post(
  "/vehicle/add", authorize, tenant.AddTenantVehicleInfo
);
router.post(
  "/vehicle/update", authorize, tenant.EditVehicleInfo
);
router.post(
  "/vehicle/delete", authorize, tenant.DeleteVehicleInfo
);
router.get(
  "/vehicle/list", authorize, tenant.GetTenantVehicleInfo
);

export default router;
