package org.dromara.main.controller.miniapp;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.main.domain.bo.MainPositionBo;
import org.dromara.main.domain.vo.MainPositionVo;
import org.dromara.main.service.IMainPositionService;
import org.dromara.main.service.IMainStudentDislikeService;
import org.springframework.web.bind.annotation.*;

/**
 * 小程序端 - 岗位查询接口
 * 使用 @SaIgnore 跳过平台鉴权，允许小程序用户直接访问
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/miniapp/position")
public class MiniappPositionController {

    private final IMainPositionService mainPositionService;

    private final IMainStudentDislikeService studentDislikeService;

    /**
     * 小程序端 - 查询岗位分页列表（公开接口，无需平台权限）
     */
    @SaIgnore
    @GetMapping("/list")
    public TableDataInfo<MainPositionVo> list(MainPositionBo bo, PageQuery pageQuery) {
        return TableDataInfo.build(mainPositionService.queryPageList(bo, pageQuery));
    }

    /**
     * 小程序端 - 获取岗位详情（公开接口，无需平台权限）
     */
    @SaIgnore
    @GetMapping("/{id}")
    public R<MainPositionVo> getInfo(@PathVariable Long id) {
        return R.ok(mainPositionService.queryById(id));
    }

    /** 屏蔽岗位或公司 */
    @SaIgnore
    @PostMapping("/dislike")
    public R<Void> dislike(@RequestParam Long studentId,
                           @RequestParam String type,        // "1"=岗位 "2"=公司
                           @RequestParam(required = false) Long positionId,
                           @RequestParam(required = false) String tenantId) {
        if ("1".equals(type) && positionId != null) {
            studentDislikeService.dislikePosition(studentId, positionId);
        } else if ("2".equals(type) && tenantId != null) {
            studentDislikeService.dislikeCompany(studentId, tenantId);
        }
        return R.ok();
    }

}
