package com.vetti.web.controller.hotake;

import com.vetti.common.annotation.Log;
import com.vetti.common.core.controller.BaseController;
import com.vetti.common.core.domain.R;
import com.vetti.common.core.page.TableWebDataInfo;
import com.vetti.common.enums.BusinessType;
import com.vetti.hotake.domain.HotakeAccessibility;
import com.vetti.hotake.service.IHotakeAccessibilityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户无障碍设置Controller
 *
 * @author vetti
 * @date 2026-02-01
 */
@Api(tags = "用户无障碍设置")
@RestController
@RequestMapping("/hotake/accessibility")
public class HotakeAccessibilityController extends BaseController {
    @Autowired
    private IHotakeAccessibilityService hotakeAccessibilityService;

    /**
     * 查询用户无障碍设置列表
     */
    @ApiOperation("查询用户无障碍设置列表(分页)")
    @GetMapping("/getPagelist")
    public TableWebDataInfo<HotakeAccessibility> list(HotakeAccessibility hotakeAccessibility) {
        startPage();
        hotakeAccessibility.setCreateBy(getUsername());
        List<HotakeAccessibility> list = hotakeAccessibilityService.selectHotakeAccessibilityList(hotakeAccessibility);
        return getWebDataTable(list);
    }

    /**
     * 查询用户无障碍设置列表
     */
    @ApiOperation("查询用户无障碍设置列表(无分页)")
    @GetMapping("/getList")
    public R<List<HotakeAccessibility>> getList(HotakeAccessibility hotakeAccessibility) {
        hotakeAccessibility.setCreateBy(getUsername());
        List<HotakeAccessibility> list = hotakeAccessibilityService.selectHotakeAccessibilityList(hotakeAccessibility);
        return R.ok(list, "");
    }

    /**
     * 获取用户无障碍设置详细信息
     */
    @ApiOperation("获取用户无障碍设置详细信息")
    @GetMapping(value = "/{id}")
    public R<HotakeAccessibility> getInfo(@ApiParam("设置ID") @PathVariable("id") Integer id) {
        return R.ok(hotakeAccessibilityService.selectHotakeAccessibilityById(id), "");
    }

    /**
     * 新增用户无障碍设置
     */
    @ApiOperation("新增用户无障碍设置")
    @Log(title = "用户无障碍设置", businessType = BusinessType.INSERT)
    @PostMapping
    public R<HotakeAccessibility> add(@RequestBody HotakeAccessibility hotakeAccessibility) {
        return R.ok(hotakeAccessibilityService.insertHotakeAccessibility(hotakeAccessibility));
    }

    /**
     * 修改用户无障碍设置
     */
    @ApiOperation("修改用户无障碍设置")
    @Log(title = "用户无障碍设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<HotakeAccessibility> edit(@RequestBody HotakeAccessibility hotakeAccessibility) {
        return R.ok(hotakeAccessibilityService.updateHotakeAccessibility(hotakeAccessibility));
    }

    /**
     * 删除用户无障碍设置
     */
    @ApiOperation("删除用户无障碍设置")
    @Log(title = "用户无障碍设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R remove(@PathVariable Integer id) {
        return R.ok(hotakeAccessibilityService.deleteHotakeAccessibilityById(id));
    }

    /**
     * 获取当前登录用户的无障碍设置
     * 如果不存在则自动创建默认设置
     */
    @ApiOperation("获取当前登录用户的无障碍设置")
    @GetMapping("/getCurrentUser")
    public R<HotakeAccessibility> getCurrentUserAccessibility() {
        String username = getUsername();
        HotakeAccessibility accessibility = hotakeAccessibilityService.getCurrentUserAccessibility(username);
        return R.ok(accessibility, "");
    }

}
