package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.entity.HospitalDept;

import java.util.List;

@Mapper
public interface HospitalDeptMapper {
    
    /**
     * 查询所有科室
     * @return 科室列表
     */
    @Select("SELECT code, out_code AS outCode, name, address, telephone, introduction, enabled, remark FROM tb_hospital_dept")
    List<HospitalDept> findAll();
    
    /**
     * 根据科室代码查询科室
     * @param code 科室代码
     * @return 科室信息
     */
    @Select("SELECT code, out_code AS outCode, name, address, telephone, introduction, enabled, remark FROM tb_hospital_dept WHERE code = #{code}")
    HospitalDept findByCode(String code);
    
    /**
     * 插入新科室
     * @param dept 科室信息
     */
    @Insert("INSERT INTO tb_hospital_dept(code, out_code, name, address, telephone, introduction, enabled, remark) " +
            "VALUES(#{code}, #{outCode}, #{name}, #{address}, #{telephone}, #{introduction}, #{enabled}, #{remark})")
    void insert(HospitalDept dept);
    
    /**
     * 更新科室信息
     * @param dept 科室信息
     */
    @Update("UPDATE tb_hospital_dept SET out_code=#{outCode}, name=#{name}, address=#{address}, telephone=#{telephone}, " +
            "introduction=#{introduction}, enabled=#{enabled}, remark=#{remark} WHERE code=#{code}")
    void update(HospitalDept dept);
    
    /**
     * 根据科室代码删除科室
     * @param code 科室代码
     */
    @Delete("DELETE FROM tb_hospital_dept WHERE code = #{code}")
    void deleteByCode(String code);
}