package cn.iocoder.yudao.module.base.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.base.entity.DriveSchoolAddress;
import cn.iocoder.yudao.module.base.service.DriveSchoolAddressService;
import cn.iocoder.yudao.module.base.vo.DlDriveSchoolStudentVO;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 地址管理")
@RestController
@RequestMapping("/address")
@Validated
public class DriveSchoolAddressController {

    @Resource
    private DriveSchoolAddressService addressService;

    /**
     * 查满足条件的所有地址
     *
     * @param type 地点类型（0-训练|1-考试）
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
     * @author vinjor-M
     * @date 18:38 2025/2/6
     **/
    @GetMapping("/getList")
    @Operation(summary = "查满足条件的所有地址")
    public CommonResult<?> getList(Integer type, String subject) {
        return success(addressService.getList(type, subject, null));
    }

    /**
     * 分页查询地址
     * @param pageReqVO 请求参数
     * @param pageNo    页码
     * @param pageSize  每页条数
     * @return
     */
    @GetMapping("/page")
    public CommonResult<?> page(@Valid DriveSchoolAddress pageReqVO,
                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<DriveSchoolAddress> page = new Page<>(pageNo, pageSize);
        Page<DriveSchoolAddress> resultPage = addressService.page(page, Wrappers.<DriveSchoolAddress>lambdaQuery());
        return success(resultPage);
    }

    /**
     * 根据id查询地址
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public CommonResult<?> getById(@PathVariable("id") String id) {
        DriveSchoolAddress address = addressService.getById(id);
        return success(address);
    }


    /**
     * 新增地址
     * @param address 新增的地址信息
     * @return
     */
    @PostMapping
    public CommonResult<?> add(@RequestBody @Valid DriveSchoolAddress address) {
        addressService.save(address);
        return success(address);
    }

    /**
     * 修改地址
     * @param address 修改后的地址信息
     * @return
     */
    @PutMapping
    public CommonResult<?> update(@RequestBody @Valid DriveSchoolAddress address) {
        addressService.updateById(address);
        return success(address);
    }

    /**
     * 删除地址
     * @param id id
     * @return
     */
    @DeleteMapping("/{id}")
    public CommonResult<?> delete(@PathVariable("id") String id) {
        addressService.removeById(id);
        return success(null);
    }
}