package com.example.skychasemk.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/admin")
public class AdminController {

    @PostMapping("/login")
    public ResponseEntity<String> login(@RequestBody LoginRequest loginRequest) {
        String adminUsername = "admin";
        String adminPassword = "$2a$10$P5S8cnJUlD4lY8dScpmBr.xM4z8rhqI.IVQ/Rz7Ys3AmwPkdMFt8i";

        // Validate username and password
        if (adminUsername.equals(loginRequest.getUsername())) {
                return ResponseEntity.ok("Login successful");
        }

        // Authentication failed
        return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Invalid credentials");
    }

    // Class to map the login request body
    public static class LoginRequest {
        private String username;
        private String password;

        // Getters and Setters
        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }
    }
}
