const fastify = require("fastify");
const tanksController = require("../controllers/tanksController");
const { Tank } = require('../models/tanks')

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

    fastify.route({
        method: "POST",
        url: "/api/addTanks/:customerId",
        schema: {
          tags: ["Install"],
          description: "This is for cretae New Tank",
          summary: "This is for Create New Tank.",
          params: {
           // required: ["InstallerId"],
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "customerId",
              },
            },
          },
          body: {
            type: "object",
            properties: {
              tankhardwareId: { type: "string" },
                hardwareId: { type: "string" },
                tankName: { type: "string" },
                blockName: { type: "string"},
                capacity: { type: "string" },
               // customerId: { type: "string" },
                typeOfWater: { type: "string" },
                waterCapacityPerCm:{ type: "string" },
                tankLocation: { type: "string" },
                shape:{ type: "string" },
                height:{ type: "string" },
                width:{ type: "string" },
                length:{ type: "string" },
                need_sensor:{type:"string"}
            },
          },
          security: [
            {
              basicAuth: [],
            },
          ],
    
        },
        preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.addTanks,
        // onResponse: (request, reply) => {
        //   validationHandler.sendPhoneVerificationCode(request, reply);
        // },
        //onResponse: validationHandler.sendPhoneVerificationCode,
      });

      fastify.route({
        method: "PUT",
        url: "/api/updateTanks/:customerId",
        schema: {
          tags: ["Install"],
          summary: "This is for update tank",
          params: {
            required: ["customerId"],
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "customerId",
              },
            },
          },
          querystring: {
            tankName: {type: 'string'}
          },
          
          body: {
            type: "object",
            // required: ['phone'],
            properties: {
             
              tankhardwareId: { type: "string" },
              hardwareId: { type: "string" },
             
              blockName: { type: "string"},
              capacity: { type: "string" },
              shape: { type: "string" },
             // customerId: { type: "string" },
              typeOfWater: { type: "string" },
              waterCapacityPerCm:{ type: "string" },
              tankLocation: { type: "string" },
              height:{ type: "string" },
              width:{ type: "string" },
              length:{ type: "string" },
              need_sensor:{type:"string"}
            },
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        // preHandler: [
        //   fastify.auth([fastify.operatorAuthenticate]),
        //   validationHandler.validatePhoneFormat,
        // ],
      //  preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.updateTanksInfo,
      });

      
      fastify.route({
        method: "PUT",
        url: "/api/deleteTank/:customerId",
        schema: {
          tags: ["Install"],
          summary: "This is for delete tank",
          params: {
            required: ["customerId"],
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "customerId",
              },
            },
          },
         
          body: {
            type: "object",
            // required: ['phone'],
            properties: {

              
                tankLocation: { type: "string", default: null },
            },
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.deleteTanksInfo,
      });

            
      fastify.route({
        method: "PUT",
        url: "/api/getConnectionsInfoOfParticularTank/:customerId",
        schema: {
          tags: ["Tank"],
          summary: "This is to get Connections Info Of ParticularTank",
          params: {
            required: ["customerId"],
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "customerId",
              },
            },
          },
         
          body: {
            type: "object",
            // required: ['phone'],
            properties: {
              tankName: {type: 'string'},
              tankLocation: { type: "string", default: null },
               
               
            },
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.getConnectionsInfoOfParticularTank,
      });


      

      fastify.get("/api/getTanks", {
        schema: {
          tags: ["Tank"],
          description: "This is to Get Tank Data",
          summary: "This is  to Get Tank Data",
          
          querystring: {
            customerId: {type: 'string'}
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
       // preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.getTank,
      });


      fastify.get("/api/getTanksensorcount/:customerId", {
        schema: {
          tags: ["Tank"],
          description: "This is to Get Tank Sensor Count and Switch Count",
          summary: "This is  to Get Tank Tank Sensor Count and Switch Count",
          
          params: {
            required: ["customerId"],
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "customerId",
              },
            },
          },
         
          security: [
            {
              basicAuth: [],
            },
          ],
        },
       // preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.getTanksensorcount,
      });




      fastify.get("/api/getTanksofParticularInstaller", {
        schema: {
          tags: ["Install"],
          description: "This is to Get Tank Data of Installer",
          summary: "This is  to Get Tank Data of Installer",
          
          querystring: {
            InstallerId: {type: 'string'}
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
       // preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.getTanksofParticularInstaller,
      });
    
      fastify.route({
        method: "PUT",
        url: "/api/updateTanklevels/:customerId",
        schema: {
          tags: ["Tank"],
          summary: "This is for updating tank levels",
          params: {
            required: ["customerId"],
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "customerId",
              },
            },

          },
         // querystring: {
        //    tankName: {type: 'string'}
       //   },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.updateTanklevels,
      });


      fastify.route({
        method: "GET",
        url: "/api/getTanklevels/:customerId",
        schema: {
          tags: ["Tank"],
          summary: "This is for getting tank levels",
          params: {
            required: ["customerId"],
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "customerId",
              },
            },
          },
         // querystring: {
        //    tankName: {type: 'string'}
       //   },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
       // preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.getTanklevels,
      });


      fastify.route({
        method: "PUT",
        url: "/api/motorAction/:customerId",
        schema: {
          tags: ["Tank"],
          summary: "This is for start and stop",
          params: {
            required: ["customerId"],
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "customerId",
              },
            },
          },
         
          
          body: {
            type: "object",
            // required: ['phone'],
            properties: {

                to: { type: "string", default: null },
                from: { type: "string", default: null },
                from_type: { type: "string" },
                to_type: { type: "string" },
                action: { type: "string" }, 
                startTime:{ type: "string" },
                threshold_type:{type:"string"},
                manual_threshold_litres:{type:"string"},
                manual_threshold_time:{type:"string"},
                stopTime:{type:"string"},
                start_instance_id:{type:"string"},
                motor_id:{type:"string"},
                phone:{type:"string"},

            },
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        // preHandler: [
        //   fastify.auth([fastify.operatorAuthenticate]),
        //   validationHandler.validatePhoneFormat,
        // ],
        //preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.motorAction,
      });


      // fastify.route({
      //   method: "PUT",
      //   url: "/api/consumption/:customerId",
      //   schema: {
      //     tags: ["Tank"],
      //     summary: "This is for getting consumption",
      //     params: {
      //       required: ["customerId"],
      //       type: "object",
      //       properties: {
      //         customerId: {
      //           type: "string",
      //           description: "customerId",
      //         },
      //       },
      //     },
       
      //  body: {
      //   type: "object",
       
      //   properties: {
 
      //       startDate:{ type: "string" },
      //       stopDate:{type:"string"},
       
      //   },
      // },
      //     security: [
      //       {
      //         basicAuth: [],
      //       },
      //     ],
      //   },
      //   //preHandler: fastify.auth([fastify.authenticate]),
      //   handler: tanksController.consumption,
      // });

      fastify.route({
        method: "PUT",
        url: "/api/consumption/:customerId",
        schema: {
          tags: ["Tank"],
          summary: "This is for getting consumption",
          params: {
            required: ["customerId"],
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "customerId",
              },
            },
          },
         
          body: {
            type: "object",
            // required: ['phone'],
            properties: {
              startDate:{ type: "string" },
              stopDate:{type:"string"},
              block:{type:"string"},
              typeofwater:{type:"string"},
               
               
            },
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        //preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.consumption,
      });



      fastify.route({
        method: "PUT",
        url: "/api/consumptiondatewiseofalltanks/:customerId",
        schema: {
          tags: ["Tank"],
          summary: "This is for getting consumption date wise of all tanks",
          params: {
            required: ["customerId"],
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "customerId",
              },
            },
          },
         
          body: {
            type: "object",
            // required: ['phone'],
            properties: {
              startDate:{ type: "string" },
              stopDate:{type:"string"},
              block:{type:"string"},
              typeofwater:{type:"string"},
               
               
            },
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        //preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.consumptiondatewiseofalltanks,
      });



      fastify.route({
        method: "PUT",
        url: "/api/calculateCapacity",
        schema: {
          tags: ["Tank"],
          summary: "This is for calculating the capacity",
        
          
          body: {
            type: "object",
            // required: ['phone'],
            properties: {
                shape:  { type: "string", default: null },
                length: { type: "string", default: null },
                width: { type: "string", default: null },
                height: { type: "string" },
               diameter:{ type: "string" },
              },
            },
            security: [
              {
                basicAuth: [],
              },
            ],
          },
          // preHandler: [
          //   fastify.auth([fastify.operatorAuthenticate]),
          //   validationHandler.validatePhoneFormat,
          // ],
          preHandler: fastify.auth([fastify.authenticate]),
          handler: tanksController.calculateCapacity,
        });
  

        

        fastify.route({
          method: "POST",
          url: "/api/APIWrite",
          schema: {
            tags: ["Tank"],
            description: "This is for creating an IOT Device",
            summary: "this is to Create IOT Device",
            body: {
              type: "object",
              properties: {
                hardwareId: { type: "string" },
                mode: { type: "string" },
                tanks: {
                  type: "array",
                  items: {
                    type: "object",
                    properties: {
                      tankhardwareId: { type: "string" },
                      tankHeight: { type: "string" },
                      maxLevel: { type: "string" },
                      minLevel: { type: "string" }
                    },
                    required: ["tankhardwareId", "tankHeight", "maxLevel", "minLevel"]
                  }
                }
              },
              
              required: ["hardwareId", "mode", "tanks"]
            },
            security: [
              {
                basicAuth: []
              }
            ]
          },
          handler: tanksController.IotDevice
        });
        
        fastify.route({
          method: "POST",
          url: "/api/validateRange",
          schema: {
            tags: ["Tank"],
            description: "Validate tank height range",
            summary: "Validate tank height range",
            body: {
              type: "object",
              properties: {
                tankhardwareId: { type: "string" },
                hardwareId: { type: "string" }

               
              },
              required: ["tankhardwareId"]
            },
          
          },
          handler: tanksController.validateTankHeight
        });
        
        fastify.route({
          method: "POST",
          url: "/api/adjustMeasurement",
          schema: {
            tags: ["Tank"],
            description: "Adjusts the water level measurement based on manual height measurement.",
            summary: "Calculate water level difference using measured height.",
            body: {
              type: "object",
              properties: {
                tankName: { type: "string" },
                measuredHeight: { type: "number" }
              },
              required: ["tankName", "measuredHeight"]
            },
            response: {
              200: {
                type: "object",
                properties: {
                  status_code: { type: "number" },
                  data: {
                    type: "object",
                    properties: {
                      tankName: { type: "string" },
                      originalHeight: { type: "number" },
                      measuredHeight: { type: "number" },
                      heightDifference: { type: "number" },
                      heightDifferenceInCm: { type: "number" },
                      calculatedWaterLevel: { type: "number" },
                      actualWaterLevel: { type: "number" },
                      originalPercentage: { type: "string" },
                      calculatedPercentage: { type: "string" },
                      percentageDifference: { type: "string" },
                      message: { type: "string" }
                    }
                  }
                }
              }
            }
          },
          handler: tanksController.adjustMeasurement
        });
        

        fastify.route({
          method: "POST",
          url: "/api/APIWriteforstandalone",

          schema: {
            tags: ["Tank"],
            description: "This is for creating an IOT Device for slave integrated in master",
            summary: "this is to Create IOT Device for   slave integrated in master",
            body: {
              type: "object",
              properties: {
                hardwareId: { type: "string" },
                Motor_status: { type: "string" },
                tanks: {
                  type: "array",
                  items: {
                    type: "object",
                    properties: {
                      tankhardwareId: { type: "string" },
                      tankHeight: { type: "string" }
                    },
                    required: ["tankhardwareId", "tankHeight"]
                  }
                }
              },
              required: ["hardwareId", "Motor_status", "tanks"]
            },
            security: [
              {
                basicAuth: []
              }
            ]
          },
          handler: tanksController.IotDeviceforstandalonedevice
        });
        

        

        

      fastify.get("/api/APIRead", {
        schema: {
          tags: ["Tank"],
          description: "This is for Get IOT Data",
          summary: "This is for to Get IOT Data",
          querystring: {
            hardwareId: {type: 'string'}
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },

        //preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.getIotD,
      });
      
      fastify.route({
        method: "GET",
        url: "/api/calculateTimedifference/:hardwareId",
        schema: {
          tags: ["Tank"],
          summary: "This is for calculating the time gap between iot data",
          params: {
            required: ["hardwareId"],
            type: "object",
            properties: {
              hardwareId: {
                type: "string",
                description: "hardwareId",
              },
            },
          },
         // querystring: {
        //    tankName: {type: 'string'}
       //   },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.getLatestData,
      });

      fastify.route({
        method: "GET",
        url: "/api/changesurveystatus/:customerId",
        schema: {
          tags: ["Install"],
          summary: "This is for changing survey status",
          params: {
            required: ["customerId"],
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "customerId",
              },
            },
          },
         // querystring: {
        //    tankName: {type: 'string'}
       //   },
       body: {
        type: 'object',
        properties: {
          survey_status: { type: 'string' },
        },
        required: ['survey_status'],
      },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
      //  preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.changesurveystatus,
      });


      fastify.route({
        method: "GET",
        url: "/api/checkStatusofIot",
        schema: {
          tags: ["Tank"],
          summary: "This is for checking the status of iots",
     
         // querystring: {
        //    tankName: {type: 'string'}
       //   },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.checkStatusofIot,
      });

      
      fastify.route({
        method: 'GET',
        url: '/waterlevel-sum',
       
        schema: {
          tags: ["Tank"],
          description: "This is for water level sum",
          summary: "This is forwater level sum.",
          querystring: {
            type: 'object',
            properties: {
              tankLocation: { type: 'string' },
              typeOfWater: { type: 'string' }
            },
            required: ['tankLocation', 'typeOfWater']
          },
          response: {
            200: {
              type: 'object',
              properties: {
                waterlevelSum: { type: 'integer' }
              }
            }
          }
        },
        handler: tanksController.totalwaterLevelSum
      });
      

      fastify.route({
        method: 'POST',
        url: '/update-waterlevel',
        schema: {
          tags: ['Tank'],
          description: 'This is for updating waterlevel of a tank based on its IOTtank document',
          summary: 'This is for updating waterlevel of a tank',
          body: {
            type: 'object',
            properties: {
              hardwareId: { type: 'string' },
            },
            required: ['hardwareId'],
          },
          response: {
            200: {
              type: 'object',
              properties: {
                message: { type: 'string' },
              },
            },
            404: {
              type: 'object',
              properties: {
                message: { type: 'string' },
              },
            },
            500: {
              type: 'object',
              properties: {
                message: { type: 'string' },
              },
            },
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        handler: tanksController.startUpdateLoop,
      });
      
      // fastify.get("/api/updatewaterlevelsatmidnight", {
      //   schema: {
      //     tags: ["Tank"],
      //     description: "This is for storing waterlevels in tank at midnight",
      //     summary: "This is for storing waterlevels in tank at midnight",
      //     querystring: {
      //       customerId: {type: 'string'}
      //     },
      //     security: [
      //       {
      //         basicAuth: [],
      //       },
      //     ],
      //   },
      //   preHandler: fastify.auth([fastify.authenticate]),
      //   handler: tanksController.updatewaterlevelsatmidnight,
      // });
      


      fastify.get("/api/deletemotordatarecordsbefore7days", {
        schema: {
          tags: ["Tank"],
          description: "This is for deleting the data before 7 days in motorsdata",
          summary: "This is for deleting the data before 7 days in motorsdata",
          querystring: {
            customerId: {type: 'string'}
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.deletemotordatarecordsbefore7days,
      });

      // fastify.get("/api/getTankmotordata", {
      //   schema: {
      //     tags: ["Tank"],
      //     description: "This is for Get Tank Motor Data",
      //     summary: "This is for to Get Tank Motor Data",
      //     querystring: {
      //       customerId: {type: 'string'}
      //     },
      //     security: [
      //       {
      //         basicAuth: [],
      //       },
      //     ],
      //   },
      //   preHandler: fastify.auth([fastify.authenticate]),
      //   handler: tanksController.getTankmotordata,
      // });



      fastify.route({
        method: "PUT",
        url: "/api/getTankmotordata/:customerId",
        schema: {
          tags: ["Tank"],
          summary: "This is for Get Tank Motor Data",
          params: {
            required: ["customerId"],
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "customerId",
              },
            },
          },
         
          body: {
            type: "object",
            // required: ['phone'],
            properties: {
              startDate:{ type: "string" },
              stopDate:{type:"string"},
              pumps:{type:"string"},
              users:{type:"string"},
           
               
               
            },
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        //preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.getTankmotordata,
      });


      fastify.get("/api/getPumpsAndUsers/:customerId", {
        schema: {
          tags: ["Tank"],
          description: "This is to Get pumps and users of particular customerId",
          summary: "This is to Get pumps and users of particular customerId",
          params: {
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "storeId",
              },
            },
            required: ["customerId"],
          },
          security: [
            {
              basicAuth: [],
            },
          ],
        },
        // preHandler: fastify.auth([fastify.authenticate]),
        handler: tanksController.getPumpsAndUsers,
      });
      



      fastify.post('/api/motor/write', {
        schema: {
          tags: ["Tank"],
          description: "This is to Write the motor status from  iot",
          summary: "This is to Write the motor status from  iot",
          body: {
            type: 'object',
            required: ['motor_id', 'status'],
            properties: {
              
              motor_id: { type: 'string' },
              status: { type: 'string'},
              current: { type: 'string' },
              temp: { type: 'string' },
            },
          },
      
        },
        handler: tanksController.writeMotorStatus

        
      });


      

      fastify.get('/api/motor/read', {
        schema: {
          tags: ["Tank"],
          description: "This is to Read the motor status",
          summary: "This is to Read the motor status",
          querystring: {
            type: 'object',
            properties: {
              motor_id: { type: 'string' },
            
            },
           // required: ['motor_id'],
          },
          
          
  
        },
        handler: tanksController.readMotorStatus
      });


      fastify.get('/api/motor/readMotorIotStatus', {
        schema: {
          tags: ["Tank"],
          description: "This is to Read the motor status from Iot",
          summary: "This is to Read the motor status from Iot",
          querystring: {
            type: 'object',
            properties: {
              motor_id: { type: 'string' },
            
            },
           // required: ['motor_id'],
          },
          
          
  
        },
        handler: tanksController.readMotorStatusFromIot
      });

      fastify.post('/api/motor/changeMotorStatus', {
        schema: {
          tags: ["Tank"],
          description: "This is to change the motor status",
          summary: "This is to change the motor status",
  
          body: {
            type: 'object',
            properties: {
              motor_id: { type: 'string' },
              action: { type: 'string' },
             
            },
            required: ["motor_id"]
          },

        },
        handler: tanksController.changeMotorStatus
      });




  


      // fastify.post('/api/motor/write', {
      //   schema: {
      //     tags: ["Tank"],
      //     description: "This is to Write the motor status",
      //     summary: "This is to Write the motor status",
      //     body: {
      //       type: 'object',
      //       required: ['motor_id', 'status'],
      //       properties: {
      //         motor_id: { type: 'string' },
      //         status: { type: 'string', enum: ['on', 'off'] },
      //         current: { type: 'string' },
      //         temp: { type: 'string' },
      //       },
      //     },
      //     // response: {
      //     //   200: {
      //     //     type: 'object',
      //     //     properties: {
      //     //       // Define your response properties here
      //     //       motor_id: { type: 'string' },
      //     //       status: { type: 'string' },
      //     //       current: { type: 'string' },
      //     //       temp: { type: 'string' },
      //     //       // Add other properties as needed
      //     //     },
      //     //   },
      //     // },
      //   },
      //   handler: tanksController.writeMotorStatus

      // });


      // fastify.get('/api/motor/read', {
      //   schema: {
      //     tags: ["Tank"],
      //     description: "This is to Read the motor status",
      //     summary: "This is to Read the motor status",
      //     querystring: {
      //       type: 'object',
      //       properties: {
      //         motor_id: { type: 'string' },
      //         action: { type: 'string', enum: ['1', '2'] },
      //       },
      //       required: ['motor_id', 'action'],
      //     },
      //     // response: {
      //     //   200: {
      //     //     type: 'object',
      //     //     properties: {
      //     //       // Define your response properties here
      //     //       motor_id: { type: 'string' },
      //     //       motor_status: { type: 'string' },
      //     //       motor_speed: { type: 'string' },
      //     //       motor_temperature: { type: 'string' },
      //     //       // Add other properties as needed
      //     //     },
      //     //   },
      //     // },
      //   },
      //   handler: tanksController.readMotorStatus
      // });


      fastify.route({
        method: "PUT",
        url: "/api/update_auto_mode/:customerId",
        schema: {
          tags: ["Tank"],
          summary: "This is for changing auto mode for motor with min and max levels",
          params: {
            required: ["customerId"],
            type: "object",
            properties: {
              customerId: {
                type: "string",
                description: "customerId",
              },
            },
          },
          
          body: {
            type: "object",
            // required: ['phone'],
            properties: {
                motor_id: { type: "string", default: null },
               
                auto_mode: { type: "string", default: null },
               
              },
            },
            security: [
              {
                basicAuth: [],
              },
            ],
          },
          // preHandler: [
          //   fastify.auth([fastify.operatorAuthenticate]),
          //   validationHandler.validatePhoneFormat,
          // ],
          //preHandler: fastify.auth([fastify.authenticate]),
          handler: tanksController.update_auto_mode,
        });
      
      


        fastify.route({
          method: "PUT",
          url: "/api/update_auto_percentage/:customerId",
          schema: {
            tags: ["Tank"],
            summary: "This is for changing auto mode for motor with min and max levels",
            params: {
              required: ["customerId"],
              type: "object",
              properties: {
                customerId: {
                  type: "string",
                  description: "customerId",
                },
              },
            },
            
            body: {
              type: "object",
              // required: ['phone'],
              properties: {
                  tankName: { type: "string", default: null },
                  auto_min_percentage: { type: "string", default: null },
                  auto_max_percentage: { type: "string", default: null },
                  tankLocation: { type: "string", default: null },
                  auto_mode_type: { type: "string", default: "default" },
                 
                },
              },
              security: [
                {
                  basicAuth: [],
                },
              ],
            },
            // preHandler: [
            //   fastify.auth([fastify.operatorAuthenticate]),
            //   validationHandler.validatePhoneFormat,
            // ],
            //preHandler: fastify.auth([fastify.authenticate]),
            handler: tanksController.update_auto_percentage,
          });


          fastify.route({
            method: "GET",
            url: "/api/getBlockData/:customerId",
            schema: {
              tags: ["Tank"],
              summary: "This is for get blocks under particular user",
              params: {
                required: ["customerId"],
                type: "object",
                properties: {
                  customerId: {
                    type: "string",
                    description: "customerId",
                  },
                },
              },
             // querystring: {
            //    tankName: {type: 'string'}
           //   },
              security: [
                {
                  basicAuth: [],
                },
              ],
            },
            //preHandler: fastify.auth([fastify.authenticate]),
            handler: tanksController.getBlockData,
          });


          fastify.route({
            method: "GET",
            url: "/api/getCustomerAutoPercentages/:customerId",
            schema: {
              tags: ["Tank"],
              summary: "This is to get auto mode default percentages",
              params: {
                required: ["customerId"],
                type: "object",
                properties: {
                  customerId: {
                    type: "string",
                    description: "customerId",
                  },
                },
              },
             // querystring: {
            //    tankName: {type: 'string'}
           //   },
              security: [
                {
                  basicAuth: [],
                },
              ],
            },
            //preHandler: fastify.auth([fastify.authenticate]),
            handler: tanksController.getCustomerAutoPercentages,
          });
        
          fastify.route({
            method: "PUT",
            url: "/api/consumptionofparticulartank/:customerId",
            schema: {
              tags: ["Tank"],
              summary: "This is for getting consumption of a particular tank",
              params: {
                required: ["customerId"],
                type: "object",
                properties: {
                  customerId: {
                    type: "string",
                    description: "Customer ID",
                  },
                },
              },
              body: {
                type: "object",
                properties: {
                  tankName: { type: "string", description: "Tank name" },
                  tankLocation: { type: "string", description: "Tank location" },
                  startDate: { type: "string", description: "Start date" },
                  stopDate: { type: "string", description: "Stop date" },
                  block: { type: "string", description: "Block name" },
                },
              },
              security: [
                {
                  basicAuth: [],
                },
              ],
            },
            // preHandler: fastify.auth([fastify.authenticate]),
            handler: tanksController.consumptionofparticulartank,
          });
         
          
          fastify.route({
            method: "PUT",
            url: "/api/getPendingAndCompletedsurveyOfparticularInstaller/:installationId",
            schema: {
              tags: ["Install"],
              summary: "This is for getting pending and completed surveys users of particular installer",
              params: {
                required: ["installationId"],
                type: "object",
                properties: {
                  installationId: {
                    type: "string",
                    description: "InstallationId",
                  },
                },
              },
              body: {
                type: "object",
                properties: {
                  survey_status: { type: "string" },
                
                },
              },
              security: [
                {
                  basicAuth: [],
                },
              ],
            },
            // preHandler: fastify.auth([fastify.authenticate]),
            handler: tanksController.getPendingAndCompletedsurveyOfparticularInstaller,
          });
          

          fastify.route({
            method: "PUT",
            url: "/api/updatetankstatus/:customerId",
            schema: {
              tags: ["Tank"],
              summary: "This is for updating tank status to active or inactive",
              params: {
                required: ["customerId"],
                type: "object",
                properties: {
                  customerId: {
                    type: "string",
                    description: "customerId",
                  },
                },
              },
             
              body: {
                type: "object",
                // required: ['phone'],
                properties: {
                  tankName:{ type: "string" },
                  tankLocation:{type:"string"},
                  status:{type:"string"},
                
                   
                },
              },
              security: [
                {
                  basicAuth: [],
                },
              ],
            },
            //preHandler: fastify.auth([fastify.authenticate]),
            handler: tanksController.updatetankstatus,
          });
          fastify.route({
            method: "POST",
            url: "/api/sendNotificationDaily",
            schema: {
              tags: ["Tank"],
              summary: "This is for time-based notification",
              body: {
                type: "object",
                properties: {
                  customerId: { type: "string" },
                  notificationTime: { type: "string" },
                  allowNotifications: { type: "boolean" }, 
                },
                required: ["customerId", "notificationTime", "allowNotifications"], // Ensures all fields are required
              },
              security: [{ basicAuth: [] }],
            },
            handler: tanksController.sendUserSetNotifications,
          });
          
          fastify.route({
            method: "POST",
            url: "/api/sendNotificationLowWaterLevel",
            schema: {
              tags: ["Tank"],
              summary: "This is for Send low water level alert notification",
              body: {
                type: "object",
                properties: {
                  customerId: { type: "string" },
                  lowWaterAlert: { type: "boolean" }, 
                },
                required: ["customerId", "lowWaterAlert"], // Ensures all fields are required
              },
              security: [{ basicAuth: [] }],
            },
            handler: tanksController.sendUserSetLowWaterNotificationsSwitch,
          });

          fastify.route({
            method: "POST",
            url: "/api/sendNotificationCriticallyWaterLevel",
            schema: {
              tags: ["Tank"],
              summary: "This is for Send critically low water level alert notification",
              body: {
                type: "object",
                properties: {
                  customerId: { type: "string" },
                  criticalLowWaterAlert: { type: "boolean" }, 
                },
                required: ["customerId", "criticalLowWaterAlert"], // Ensures all fields are required
              },
              security: [{ basicAuth: [] }],
            },
            handler: tanksController.sendUserSetCriticallyLowWaterNotificationsSwitch,
          });
          fastify.route({
            method: "POST",
            url: "/api/sendNotificationManualStartAndStop",
            schema: {
              tags: ["Tank"],
              summary: "This is for Send Manual start and stop alert notification",
              body: {
                type: "object",
                properties: {
                  customerId: { type: "string" },
                  manualStartAndStopNotify: { type: "boolean" }, 
                },
                required: ["customerId", "manualStartAndStopNotify"], // Ensures all fields are required
              },
              security: [{ basicAuth: [] }],
            },
            handler: tanksController.sendUserManualStartAndStop,
          });
          fastify.route({
            method: "POST",
            url: "/api/sendNotificationAutomaticStartAndStop",
            schema: {
              tags: ["Tank"],
              summary: "This is for Send Automatic start and stop alert notification",
              body: {
                type: "object",
                properties: {
                  customerId: { type: "string" },
                  automaticStartAndStopNotify: { type: "boolean" }, 
                },
                required: ["customerId", "automaticStartAndStopNotify"], // Ensures all fields are required
              },
              security: [{ basicAuth: [] }],
            },
            handler: tanksController.sendUserAutomaticStartAndStop,
          });

          fastify.route({
            method: "POST",
            url: "/api/sendNotificationDailyPreference",
            schema: {
              tags: ["Tank"],
              summary: "This is for time based notification preferences",
              body: {
                type: "object",
                properties: {
                  customerId: {
                    type: "string",
  
                  },
                  notificationPreference: {
                    type: "string",
                  },
                  // allowNotifications: {
                  //   type: "boolean" 
                  // }                   
                },
              },
              security: [
                {
                  basicAuth: [],
                },
              ],
            },
            //preHandler: fastify.auth([fastify.authenticate]),
            handler: tanksController.notificationTiming,
          });


          fastify.route({
            method: "GET",
            url: "/api/listofactiveandinactivetankstatus/:customerId",
            schema: {
              tags: ["Tank"],
              summary: "Get list of active or inactive tanks",
              params: {
                required: ["customerId"],
                type: "object",
                properties: {
                  customerId: { type: "string", description: "Customer ID" },
                },
              },
              querystring: {
                type: "object",
                properties: {
                  status: { type: "string"},
                },
              },
              security: [{ basicAuth: [] }],
            },
            handler: tanksController.listofactiveandinactivetankstatus,
          });
          

    next();
}
