package com.ycwl.basic.controller.pc;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity;
import com.ycwl.basic.model.pc.scenic.req.ScenicAccountReqQuery;
import com.ycwl.basic.service.pc.ScenicAccountService;
import com.ycwl.basic.utils.ApiResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@RestController
@RequestMapping("/api/scenicAccount/v1")
public class ScenicAccountController {
    @Autowired
    private ScenicAccountService service;

    // 添加景区账号
    @PostMapping("/add")
    public ApiResponse addScenicAccount(@RequestBody ScenicAccountEntity entity) {
        int result = service.addScenicAccount(entity);
        return result > 0 ? ApiResponse.success("添加成功") : ApiResponse.fail("添加失败");
    }

    // 删除景区账号
    @DeleteMapping("/delete/{id}")
    public ApiResponse deleteScenicAccount(@PathVariable Long id) {
        int result = service.deleteScenicAccount(id);
        return result > 0 ? ApiResponse.success("删除成功") : ApiResponse.fail("删除失败");
    }
    @PostMapping("/updateStatus/{id}")
    public ApiResponse updateStatus(@PathVariable Long id) {
        int result = service.updateStatus(id);
        return result > 0 ? ApiResponse.success("更新成功") : ApiResponse.fail("更新失败");
    }

    // 更新景区账号
    @PostMapping("/update")
    public ApiResponse updateScenicAccount(@RequestBody ScenicAccountEntity entity) {
        int result = service.updateScenicAccount(entity);
        return result > 0 ? ApiResponse.success("更新成功") : ApiResponse.fail("更新失败");
    }

    // 根据ID查询景区账号
    @GetMapping("/get/{id}")
    public ApiResponse getScenicAccount(@PathVariable Long id) {
        ScenicAccountEntity entity = service.getScenicAccountById(id);
        return entity != null ? ApiResponse.success(entity) : ApiResponse.fail("未找到该账号");
    }

    // 根据景区ID查询超级账号
    @GetMapping("/super/{scenicId}")
    public ApiResponse getSuperAccount(@PathVariable Long scenicId) {
        ScenicAccountEntity entity = service.getSuperAccountByScenicId(scenicId);
        return entity != null ? ApiResponse.success(entity) : ApiResponse.fail("未找到超级账号");
    }

    // 新增分页查询接口
    @PostMapping("/page")
    public ApiResponse<PageInfo<ScenicAccountEntity>> pageQuery(@RequestBody ScenicAccountReqQuery req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        List<ScenicAccountEntity> list = service.pageQuery(req);
        PageInfo<ScenicAccountEntity> pageInfo = new PageInfo<>(list);
        return ApiResponse.success(pageInfo);
    }
}