const departmentController = require('../controllers/departmentController')

module.exports = function (fastify, opts, next) {

    fastify.route({
        method: "POST",
        url: "/api/citySignup",
        schema: {
          tags: ["Department"],
          description: "This is for creating a new City account",
          summary: "This is for creating a new City account",
          body: {
            type: "object",
            properties: {
              phone: { type: "string" },
              city: { type: "string" },
              officeName: { type: "string" },
              location: {
                type: "array",
                items: { type: "string" },
              },
              state: { type: "string" },
              email: { type: "string" },
              country: { type: "string" },
              office_address1: { type: "string" },
              address2: { type: "string" },
              zone: { type: "string" },
              pincode: { type: "string" },
              //departmentName: { type: "string" },
            },
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        handler: departmentController.addCity,
      });
      
    
    // fastify.get("/api/getSingledepartmentData/:departmentId", {
    //     schema: {
    //       tags: ["Department"],
    //       description: "This is for Get Single departmentId Data",
    //       summary: "This is to Get Single departmentId Data",
    //       params: {
    //         type: "object",
    //         properties: {
    //             departmentId: {
    //             type: "string",
    //             description: "departmentId", 
    //           },
    //         },
    //       },
          
    //       security: [
    //         {
    //           basicAuth: [],
    //         },
    //       ],
    //     },
    //     handler: departmentController.getSinledepartmentData,
    //   });
   
      // fastify.get("/api/getallcities", {
      //   schema: {
      //     tags: ["Department"],
      //     description: "This is for Get all cities Data",
      //     summary: "This is for to Get all cities Data",
         
      //     security: [
      //       {
      //         basicAuth: [],
      //       },
      //     ],
      //   },
      //   //preHandler: fastify.auth([fastify.authenticate]),
      //   handler: departmentController.getallcities,
      // });

       
    //   fastify.get("/api/getalldepartmentsParticularFileds", {
    //     schema: {
    //       tags: ["Department"],
    //       description: "This is for Get all Department particular fileds Data",
    //       summary: "This is for to Get all Department particular fields Data",
         
    //       security: [
    //         {
    //           basicAuth: [],
    //         },
    //       ],
    //     },
    //     //preHandler: fastify.auth([fastify.authenticate]),
    //     handler: departmentController.getAllDepartmentsParticularFields,
    //   });

      fastify.get("/api/getallcompanyNames", {
        schema: {
          tags: ["Department"],
          description: "This is for Get all Company Name in city schema ",
          summary: "This is for to Get all Company Name in city schema ",
         
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        //preHandler: fastify.auth([fastify.authenticate]),
        handler: departmentController.getallCompanyNames,
      });


      fastify.delete("/api/deletecity/:cityId", {
        schema: {
          description: "Delete a city by cityId",
          tags: ["Department"],
          summary: "Delete a user by city",
          params: {
            type: "object",
            properties: {
                cityId: { type: "string" },  
            },
            required: ["cityId"],
          },
          response: {
            200: {
              type: "object",
              properties: {
                success: { type: "boolean" },
                message: { type: "string" },
              }
            }
          }
        },
        handler: departmentController.deletecityInfo,
      });

      fastify.put('/api/editcity/:cityId', {
        schema: {
          description: "Edit City details by cityId",
          tags: ["Department"],
          summary: "Edit City  details.",
          params: {
            type: "object",
            properties: {
                cityId: { type: "string" },  
            },
            required: ["cityId"],
          },
          body: {
            type: "object",
            properties: {
                phone: { type: "string" },
                city: { type: "string" },
                state: { type: "string" },
                country: { type: "string" },
                address1: { type: "string" },
                address2: { type: "string" },
                zone: { type: "string" },
                pincode: { type: "string" },
                officeName: { type: "string" },
                email: { type: "string" },
    
              },
              }
            },
        handler: departmentController.editcity,
      });

      
    fastify.route({
        method: "POST",
        url: "/api/departmentSignup",
        schema: {
          tags: ["Department"],
          description: "This is for creating a new Team Member Account",
          summary: "This is for creating a new Team Member Account",
          body: {
            type: "object",
            //required: ["phone", "username", "password", "role"],  // Add role to required fields
            properties: {
              phone: { type: "string" },
              password: { type: "string" },
              alternativeContactNumber: { type: "string" },
              personalEmail: { type: "string" },
              gender: { type: "string" },
              city: { type: "string" },
              state: { type: "string" },
              country: { type: "string" },
              address1: { type: "string" },
              address2: { type: "string" },
              zone: { type: "string" },
              pincode: { type: "string" },
              desginationName: { type: "string" },
              departmentName: { type: "string" },
              firstName: { type: "string" },
              lastName: { type: "string" },
              reportingManager: { type: "string",  default: "Self" },
              email: { type: "string" },
              personal_city: { type: "string"},
              officeName: { type: "string"},
              reportingManager_mobile_number: { type: "string"},
              reportingManager_email: { type: "string"},
              picture: { type: "string"},
              dateOfJoin: { type: "string"},
              location: {
                type: "array",
                items: { type: "string" },
              },
            },
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        handler: departmentController.addDepartment,
      });
      
      fastify.get("/api/getSingledepartmentData/:departmentId", {
          schema: {
            tags: ["Department"],
            description: "This is for Get Single departmentId Data",
            summary: "This is to Get Single departmentId Data",
            params: {
              type: "object",
              properties: {
                departmentId: {
                  type: "string",
                  description: "departmentId", 
                },
              },
            },
            
            security: [
              {
                basicAuth: [],
              },
            ],
          },
          handler: departmentController.getSinledepartmentData,
        });
     
        fastify.get("/api/getalldepartments", {
          schema: {
            tags: ["Department"],
            description: "This is for Get all departments Data",
            summary: "This is for to Get all departments Data",
           
            security: [
              {
                basicAuth: [],
              },
            ],
          },
          //preHandler: fastify.auth([fastify.authenticate]),
          handler: departmentController.getalldepartments,
        });

        fastify.get("/api/getallcitiesdata", {
          schema: {
            tags: ["Department"],
            description: "This is for Get all Cities Data for City Schema",
            summary: "This is for to Get all Cities Data for City Schema",
           
            security: [
              {
                basicAuth: [],
              },
            ],
          },
          //preHandler: fastify.auth([fastify.authenticate]),
          handler: departmentController.getallCitiesData,
        });
        fastify.get("/api/getallzonesdata", {
          schema: {
            tags: ["Department"],
            description: "This is for Get all Zones Data for City Schema",
            summary: "This is for to Get all Zones Data for City Schema",
           
            security: [
              {
                basicAuth: [],
              },
            ],
          },
          //preHandler: fastify.auth([fastify.authenticate]),
          handler: departmentController.getallZonesData,
        });

        fastify.get("/api/getalllocationsdata", {
          schema: {
            tags: ["Department"],
            description: "This is for Get all Locations Data for City Schema",
            summary: "This is for to Get all Locations Data for City Schema",
           
            security: [
              {
                basicAuth: [],
              },
            ],
          },
          //preHandler: fastify.auth([fastify.authenticate]),
          handler: departmentController.getallLocationData,
        });

        fastify.delete("/api/deletedepartment/:departmentId", {
          schema: {
            description: "Delete a Department by departmentId",
            tags: ["Department"],
            summary: "Delete a user by departmentId",
            params: {
              type: "object",
              properties: {
                departmentId: { type: "string" },  
              },
              required: ["departmentId"],
            },
            response: {
              200: {
                type: "object",
                properties: {
                  success: { type: "boolean" },
                  message: { type: "string" },
                }
              }
            }
          },
          handler: departmentController.deletedepartmentInfo,
        });
  
        fastify.put('/api/editdesgination/:departmentId', {
          schema: {
            description: "Edit Department details by departmentId",
            tags: ["Department"],
            summary: "Edit Department  details.",
            params: {
              type: "object",
              properties: {
                departmentId: { type: "string" },  
              },
              required: ["departmentId"],
            },
            body: {
              type: "object",
              properties: {
                  phone: { type: "string" },
                  alternativeContactNumber: { type: "string" },
                  personalEmail: { type: "string" },      
                  gender: { type: "string" },
                  city: { type: "string" },
                  state: { type: "string" },
                  country: { type: "string" },
                  address1: { type: "string" },
                  address2: { type: "string" },
                  zone: { type: "string" },
                  pincode: { type: "string" },
                  desginationName: { type: "string" },
                  email: { type: "string" },
                  reportingManager: { type: "string" },
                  departmentName: { type: "string" },
                  firstName: { type: "string" },
                  lastName: { type: "string" },
                  personal_city: { type: "string"},
                  officeName: { type: "string"},
                  reportingManager_mobile_number: { type: "string"},
                  reportingManager_email: { type: "string"},
      
                },
                }
              },
          handler: departmentController.editdepartment,
        });

        // fastify.get("/api/getalldesignationsParticularFileds", {
        //     schema: {
        //       tags: ["Department"],
        //       description: "This is for Get all Designation particular fileds",
        //       summary: "This is for to Get all Designation particular fields",
             
        //       security: [
        //         {
        //           basicAuth: [],
        //         },
        //       ],
        //     },
        //     //preHandler: fastify.auth([fastify.authenticate]),
        //     handler: departmentController.getAllDesignationsParticularFields,
        //   });
    
          fastify.route({
            method: "GET",
            url: "/api/locations",
            schema: {
              tags: ["Department"],
              description: "Fetch locations by city and zone",
              summary: "Fetch locations by city and zone",
              querystring: {
                type: "object",
                required: ["city", "zone"],
                properties: {
                  city: { type: "string" },
                  zone: { type: "string" },
                },
              },
            },
            handler:departmentController.getZonebasedLocations
          });

          fastify.route({
            method: "GET",
            url: "/api/zonebasedlocations/:zone",
            schema: {
              tags: ["Department"],
              description: "Get the locations by zone",
              summary: "Get the locations by zone",
              params: {
                type: "object",
                properties: {
                  zone: { type: "string" },  
                },
              },
            },
            handler:departmentController.getLocationsByZone
          });
          
          fastify.route({
            method: "GET",
            url: "/api/zonebasedcity/:city",
            schema: {
              tags: ["Department"],
              description: "Get the zones by city",
              summary: "Get the zones by city",
              params: {
                type: "object",
                properties: {
                  city: { type: "string" },  
                },
              },
            },
            handler:departmentController.getZonesByCity
          });

          fastify.route({
            method: "GET",
            url: "/api/areabasedcity/:city",
            schema: {
              tags: ["Department"],
              description: "Get the Areas by city",
              summary: "Get the Areas by city",
              params: {
                type: "object",
                properties: {
                  city: { type: "string" },  
                },
              },
            },
            handler:departmentController.getAreasByCity
          });

          fastify.route({
            method: "GET",
            url: "/api/areabasedzones/:area",
            schema: {
              tags: ["Department"],
              description: "Get the Areas based zones",
              summary: "Get the Areas based zones",
              params: {
                type: "object",
                properties: {
                  area: { type: "string" },  
                },
              },
            },
            handler:departmentController.getZonesByArea
          });

          fastify.route({
            method: "GET",
            url: "/api/departmentNamebaselist/:officeName/:city/:departmentName",
            schema: {
              tags: ["Department"],
              description: "Department name based list",
              summary: "Department name based list",
              params: {
                type: "object",
                properties: {
                  officeName: { type: "string" },  
                  city: { type: "string" },  
                  departmentName: { type: "string" },  
                },
              },
            },
            handler:departmentController.getDepartments
          });


            fastify.get("/api/getalldepartmentNames", {
              schema: {
                tags: ["Department"],
                description: "This is for Get all departmentNames Data",
                summary: "This is for to Get all departmentNames Data",
              
                security: [
                  {
                    basicAuth: [],
                  },
                ],
              },
              //preHandler: fastify.auth([fastify.authenticate]),
              handler: departmentController.getAllDepartmentNames,
            });
            

            fastify.route({
              method: "POST",
              url: "/api/branchSignup",
              schema: {
                tags: ["Department"],
                description: "This is for creating a new Branch account",
                summary: "This is for creating a new Branch account",
                body: {
                  type: "object",
                  properties: {
                    phone: { type: "string" },
                    land_line_number: { type: "string" },
                    city: { type: "string" },
                    officeName: { type: "string" },
                    location: {
                      type: "array",
                      items: { type: "string" },
                    },
                    state: { type: "string" },
                    email: { type: "string" },
                    country: { type: "string" },
                    office_address1: { type: "string" },
                    address2: { type: "string" },
                    zone: { type: "string" },
                    pincode: { type: "string" },
                    nameoftheContactPerson: { type: "string"}
                    //departmentName: { type: "string" },
                  },
                },
                security: [
                  {
                    basicAuth: [],
                  },
                ],
              },
              handler: departmentController.addBranch,
            });

            fastify.route({
              method: "POST",
              url: "/api/zoneSignup",
              schema: {
                tags: ["Department"],
                description: "This is for creating a new Zone account",
                summary: "This is for creating a new Zone account",
                body: {
                  type: "object",
                  properties: {
                    city: { type: "string" },
                    officeName: { type: "string" },
                    location: {
                      type: "array",
                      items: { type: "string" },
                    },
                    zone: { type: "string" },
                    area : {type: "string"}
                  },
                },
                security: [
                  {
                    basicAuth: [],
                  },
                ],
              },
              handler: departmentController.addZone,
            });
            
            fastify.delete("/api/deletebranch/:branchId", {
              schema: {
                description: "Delete a city by branchId",
                tags: ["Department"],
                summary: "Delete a user by branch",
                params: {
                  type: "object",
                  properties: {
                    branchId: { type: "string" },  
                  },
                  required: ["branchId"],
                },
                response: {
                  200: {
                    type: "object",
                    properties: {
                      success: { type: "boolean" },
                      message: { type: "string" },
                    }
                  }
                }
              },
              handler: departmentController.deleteBranchInfo,
            });

            fastify.put('/api/editbranch/:branchId', {
              schema: {
                description: "Edit Branch details by branch",
                tags: ["Department"],
                summary: "Edit Branch  details.",
                params: {
                  type: "object",
                  properties: {
                      branchId: { type: "string" },  
                  },
                  required: ["branchId"],
                },
                body: {
                  type: "object",
                  properties: {
                      phone: { type: "string" },
                      land_line_number: { type: "string" },
                      city: { type: "string" },
                      state: { type: "string" },
                      country: { type: "string" },
                      address1: { type: "string" },
                      address2: { type: "string" },
                      zone: { type: "string" },
                      pincode: { type: "string" },
                      officeName: { type: "string" },
                      email: { type: "string" },
          
                    },
                    }
                  },
              handler: departmentController.editBranch,
            });

            fastify.get("/api/getCitiesByOfficeName/:officeName", {
              schema: {
                tags: ["Department"],
                description: "This is for Get cities by OfficeName Data",
                summary: "This is to Get cities by OfficeName Data",
                params: {
                  type: "object",
                  properties: {
                    officeName: {
                      type: "string",
                      description: "officeName", 
                    },
                  },
                },
                
                security: [
                  {
                    basicAuth: [],
                  },
                ],
              },
              handler: departmentController.getCitiesByOfficeName,
            });

            fastify.route({
              method: "GET",
              url: "/api/departmentNameList/:city",
              schema: {
                tags: ["Department"],
                description: "Get a list of department names for a given city",
                summary: "Department names by city",
                params: {
                  type: "object",
                  properties: {
                    city: { type: "string" }
                  },
                  required: ["city"],
                },
              },
              handler: departmentController.getDepartmentsByCity,
            });

            fastify.route({
              method: "GET",
              url: "/api/states",
              schema: {
                tags: ["Department"],
                description: "Get the States",
                summary: "Get the states",
              },
              handler:departmentController.getAllStates
            });
            
            fastify.route({
              method: "GET",
              url: "/api/states/:stateName/cities",
              schema: {
                tags: ["Department"],
                description: "Get the States by cities",
                summary: "Get the states by cites",
                params: {
                  type: "object",
                  properties: {
                    stateName: { type: "string" },  
                  },
                },
              },
              handler:departmentController.getStaeBasedCites
            });
    next();
    };