package com.yaoai.admin.plan;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.yaoai.admin.audit.annotation.AdminAudited;
import com.yaoai.admin.plan.dto.PlanUpdateRequest;
import com.yaoai.common.result.Result;
import com.yaoai.domain.entity.Plan;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin-api/plans")
@RequiredArgsConstructor
@SaCheckLogin(type = "admin")
public class PlanAdminController {

    private final PlanAdminService planAdminService;

    @GetMapping
    public Result<List<Plan>> list() {
        return Result.ok(planAdminService.list());
    }

    @PatchMapping("/{id}")
    @AdminAudited(action = "PLAN_UPDATE", resource = "PLAN", resourceIdParam = "id")
    @SaCheckRole(type = "admin", value = {"SUPER_ADMIN"})
    public Result<Plan> update(@PathVariable Long id, @RequestBody PlanUpdateRequest request) {
        return Result.ok(planAdminService.update(id, request));
    }
}
