package com.backendsys.modules.material.controller;

import com.backendsys.modules.common.aspect.SysLog;
import com.backendsys.modules.common.config.security.annotations.Anonymous;
import com.backendsys.modules.common.utils.Result;
import com.backendsys.modules.material.entity.MaterialAudit;
import com.backendsys.modules.material.entity.MaterialUser;
import com.backendsys.modules.material.service.MaterialUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Validated
@RestController
@Tag(name = "素材用户管理")
public class MaterialUserController {

    @Autowired
    private MaterialUserService materialUserService;

    @Operation(summary = "获取素材用户列表")
    @PreAuthorize("@sr.hasPermission('20.4')")
    @GetMapping("/api/material/getMaterialUserList")
    public Result getMaterialUserList(String phone, Long role_id) {
        return Result.success().put("data", materialUserService.selectMaterialUserList(phone, role_id));
    }

    @Operation(summary = "获取素材用户角色列表")
    @PreAuthorize("@sr.hasPermission('20.4')")
    @GetMapping("/api/material/getMaterialUserRoleList")
    public Result getMaterialUserRoleList() {
        return Result.success().put("data", materialUserService.selectMaterialUserRoleList());
    }

    @SysLog("审核素材用户")
    @Operation(summary = "审核素材用户")
    @PreAuthorize("@sr.hasPermission('20.4.1')")
    @PutMapping("/api/material/auditMaterialUser")
    public Result auditMaterialUser(@Validated(MaterialAudit.Audit.class) @RequestBody MaterialAudit materialAudit) {
        return Result.success().put("data", materialUserService.auditMaterialUser(materialAudit));
    }

    @Anonymous
    @SysLog("注册成为素材用户 (手机号注册)")
    @Operation(summary = "注册成为素材用户 (手机号注册)")
    @PostMapping("/api/material/registerMaterialUser")
    public Result registerMaterialUser(@Validated(MaterialUser.Register.class) @RequestBody MaterialUser materialUser) {
        return Result.success().put("data", materialUserService.registerMaterialUser(materialUser));
    }


}
