using Newtonsoft.Json.Linq;
using Tiobon.Core.Model.ViewModels.Extend;
using static Tiobon.Core.Model.Consts;

namespace Tiobon.Core.Api.Controllers;

/// <summary>
/// 个人简历(Controller)
/// </summary>
[Route("api/[controller]")]
[ApiController, GlobalActionFilter]
[Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghrh)]
public class Ghrh_ResumeController : BaseController<IGhrh_ResumeServices, Ghrh_Resume, Ghrh_ResumeDto, InsertGhrh_ResumeInput, EditGhrh_ResumeInput>
{
    public Ghrh_ResumeController(IGhrh_ResumeServices service) : base(service)
    {
    }

    #region 获取简历Tabs接口
    /// <summary>
    /// 获取简历Tabs接口
    /// </summary> 
    /// <returns></returns>
    [HttpPost("QueryViewTab")]
    public async Task<ServiceResult<List<ResumeViewTab>>> QueryViewTab() => await _service.QueryViewTab();

    /// <summary>
    /// 获取简历Tabs接口
    /// </summary> 
    /// <returns></returns>
    [HttpPost("QueryViewTab/{langId}")]
    public async Task<ServiceResult<List<ResumeViewTab>>> QueryViewTab(int langId) => await _service.QueryViewTab(langId);

    #endregion

    #region 查询
    /// <summary>
    /// 根据条件查询数据
    /// </summary>
    /// <param name="body">条件</param>
    /// <param name="status">status</param>
    /// <returns></returns>
    [HttpPost, Route("QueryList/{status}")]
    public async Task<ServicePageResult<Ghrh_ResumeDto>> QueryByStatus([FromBody] QueryBody body, string status)
    {
        var condition = "1!=1";
        switch (status)
        {
            case "All":
                condition = $"(Status ='{status}' OR Status ='{DIC_INTERVIEW_ORDER_STATUS.WaitRecommended}' OR Status ='{DIC_INTERVIEW_ORDER_STATUS.HasRecommended}' OR Status ='{DIC_INTERVIEW_ORDER_STATUS.Fail}')";
                break;
            case "Process":
                condition = $"(Status ='{status}' OR Status ='{DIC_INTERVIEW_ORDER_STATUS.WaitAppointment}' OR Status ='{DIC_INTERVIEW_ORDER_STATUS.WaitInterview}' OR Status ='{DIC_INTERVIEW_ORDER_STATUS.HasInterview}'OR Status ='{DIC_INTERVIEW_ORDER_STATUS.InterviewFail}' OR Status ='{DIC_INTERVIEW_ORDER_STATUS.Cancel}' OR Status ='{DIC_INTERVIEW_ORDER_STATUS.HasChangeDate}')";
                break;
            case "Hire":
                condition = $"(Status ='{status}' OR Status ='{DIC_INTERVIEW_ORDER_STATUS.WaitSendOffer}' OR Status ='{DIC_INTERVIEW_ORDER_STATUS.HasSendOffer}' OR Status ='{DIC_INTERVIEW_ORDER_STATUS.HasOffer}')";
                break;
            default:
                condition = $"Status ='{status}'";
                break;
        }
        return await _service.QueryFilterPage(body, condition);
    }
    #endregion

    #region 获取查询条件
    /// <summary>
    /// 获取简历Tabs接口
    /// </summary> 
    /// <returns></returns>
    [HttpPost("QueryConditions/{menuName}")]
    public async Task<ServiceResult<List<ResumeCondition>>> QueryConditions() => await _service.QueryConditions();
    #endregion

    #region 取消推荐简历
    /// <summary>
    /// 取消推荐简历
    /// </summary> 
    /// <returns></returns>
    [HttpPost("CancelRecommend")]
    public async Task<ServiceResult> CancelRecommend([FromBody] List<long> ids) => await _service.SwitchIsRecommend(ids, false);
    #endregion

    #region 回收简历
    /// <summary>
    /// 回收简历
    /// </summary> 
    /// <returns></returns>
    [HttpPost("Recovery")]
    public async Task<ServiceResult> Recovery([FromBody] List<long> ids)
    {
        bool result = await _service.Recovery(ids);
        if (result)
            return ServiceResult.OprateSuccess("回收成功！");
        return ServiceResult.OprateFailed("回收失败！");

    }
    #endregion

    #region 加入黑名单
    /// <summary>
    /// 加入黑名单
    /// </summary> 
    /// <returns></returns>
    [HttpPost("JoinBlacklist")]
    public async Task<ServiceResult> JoinBlacklist([FromBody] List<long> ids)
    {
        bool result = await _service.UpdateStatus(ids, "Blacklist");
        if (result)
            return ServiceResult.OprateSuccess("加入成功！");
        return ServiceResult.OprateFailed("加入失败！");

    }
    #endregion

    #region 加入人才库
    /// <summary>
    /// 加入人才库
    /// </summary> 
    /// <returns></returns>
    [HttpPost("JoinTalentPool")]
    public async Task<ServiceResult> JoinTalentPool([FromBody] List<long> ids)
    {
        bool result = await _service.UpdateStatus(ids, "Talent_Pool");
        if (result)
            return ServiceResult.OprateSuccess("加入成功！");
        return ServiceResult.OprateFailed("加入失败！");

    }
    #endregion

    #region 添加标签
    /// <summary>
    /// 添加标签
    /// </summary> 
    /// <returns></returns>
    [HttpPost("MarkTags")]
    public async Task<ServiceResult> MarkTags([FromBody] ResumeMarkTag markTag)
    {
        bool result = await _service.MarkTags(markTag.Ids, markTag.Tags);
        if (result)
            return ServiceResult.OprateSuccess("添加成功！");
        return ServiceResult.OprateFailed("添加失败！");

    }
    #endregion

    #region 查询简历是否存在
    /// <summary>
    /// 查询简历是否存在
    /// </summary> 
    /// <returns></returns>
    [HttpPost("CheckIsExist"), AllowAnonymous]
    public async Task<ServiceResult<dynamic>> CheckIsExist([FromBody] EditGhrh_ResumeInput input)
    {
        return await _service.CheckIsExist(input);

    }
    #endregion

    #region 查询公司配置信息
    /// <summary>
    /// 查询简历是否存在
    /// </summary> 
    /// <returns></returns>
    [HttpPost("QueryCompanyInfo/{companySpecCode}/{langId}"), AllowAnonymous]
    public async Task<ServiceResult<Dictionary<string, string>>> QueryCompanyInfo(string companySpecCode, int langId)
    {
        return await _service.QueryCompanyInfo(companySpecCode, langId);
    }
    #endregion

    #region 查询招聘表单信息接口
    /// <summary>
    /// 查询招聘表单信息接口
    /// </summary> 
    /// <returns></returns>
    [HttpPost("Query/{id}/{langId}"), AllowAnonymous]
    public async Task<ServiceResult<dynamic>> Query(long id, int langId) => await _service.Query(id, langId);

    #endregion

    #region 简历提交接口
    /// <summary>
    /// 简历提交接口
    /// </summary>
    /// <param name="id"></param>
    /// <param name="status"></param>
    /// <param name="resume"></param>
    /// <returns></returns>
    [HttpPost("Update/{id}/{status}"), AllowAnonymous]
    public async Task<ServiceResult> Submit(long id, string status, [FromBody] ResumeFormColumnSubmit resume) => await _service.Submit(id, status, resume);

    #endregion

    #region 查询招聘表单信息提交结果接口
    /// <summary>
    /// 查询招聘表单信息提交结果接口
    /// </summary> 
    /// <returns></returns>
    [HttpPost("QueryResult/{id}/{langId}"), AllowAnonymous]
    public async Task<ServiceResult<dynamic>> QueryResult(long id, int langId) => await _service.QueryResult(id, langId);

    #endregion

    #region 查询
    /// <summary>
    /// 根据条件查询数据
    /// </summary>
    /// <param name="body">条件</param>
    /// <param name="status">status</param>
    /// <returns></returns>
    [HttpPost, Route("Export/{status}")]
    public async Task<ServiceResult<string>> ExportByStatus([FromBody] QueryBody body, string status)
    {
        return await _service.Export(body, $"Status ='{status}'");
    }
    #endregion

    #region 推荐
    /// <summary>
    /// 推荐
    /// </summary>
    /// <param name="body">信息</param> 
    /// <returns></returns>
    [HttpPost, Route("Recommend")]
    public async Task<ServiceResult> Recommend([FromBody] ResumeRecommendForm body)
    {
        return await _service.Recommend(body);
    }
    #endregion

    #region 简历库已推荐提醒
    /// <summary>
    /// 简历库已推荐提醒
    /// </summary> 
    /// <param name="id">简历Id</param>
    /// <returns></returns>
    [HttpPost, Route("RemindHasRecommend")]
    public async Task<ServiceResult> RemindHasRecommend(List<long> id)
    {
        return await _service.RemindHasRecommend(id);
    }
    #endregion

    #region 面试官约面
    /// <summary>
    /// 面试官约面
    /// </summary> 
    /// <param name="id">简历Id</param>
    /// <param name="form"></param>
    /// <returns></returns>
    [HttpPost, Route("SubscribeInterview/{id}")]
    public async Task<ServiceResult> SubscribeInterview(long id, [FromBody] ResumeSubscribeInterviewForm form) => await _service.SubscribeInterview(id, form);

    #endregion

    #region 安排面试
    /// <summary>
    /// 安排面试
    /// </summary> 
    /// <param name="id">简历Id</param>
    /// <param name="body"></param>
    /// <returns></returns>
    [HttpPost, Route("ScheduleInterview/{id}")]
    public async Task<ServiceResult> ScheduleInterview(long id, [FromBody] ResumeScheduleInterviewForm body) => await _service.ScheduleInterview(id, body);

    #endregion

    #region 变更面试时间
    /// <summary>
    /// 变更面试时间
    /// </summary> 
    /// <param name="id">简历Id</param>
    /// <param name="time">时间段，2024/10/12 10:00~2024/10/12 11:00</param>
    /// <returns></returns>
    [HttpPost, Route("ModifyInterviewTime/{id}")]
    public async Task<ServiceResult> ModifyInterviewTime(long id, [FromBody] string time) => await _service.ModifyInterviewTime(id, time);
    #endregion

    #region 待面试提醒
    /// <summary>
    /// 待面试提醒
    /// </summary> 
    /// <param name="ids">简历Id，列表</param>
    /// <returns></returns>
    [HttpPost, Route("RemindWaitInterview")]
    public async Task<ServiceResult> RemindWaitInterview([FromBody] List<long> ids) => await _service.RemindWaitInterview(ids);
    #endregion

    #region 重新安排面试-直接发起新的
    /// <summary>
    /// 重新安排面试-直接发起新的
    /// </summary> 
    /// <param name="id">简历Id</param>
    /// <param name="input">input</param>
    /// <returns></returns>
    [HttpPost, Route("RescheduleInterview/{id}")]
    public async Task<ServiceResult> RescheduleInterview(long id, [FromBody] ResumeRescheduleInterviewForm input) => await _service.RescheduleInterview(id, input, "Reschedule");
    #endregion

    #region 重新预约面试-预约再发起下一轮面试
    /// <summary>
    /// 重新预约安排面试-预约再发起下一轮面试
    /// </summary> 
    /// <param name="id">简历Id</param>
    /// <param name="input">input</param>
    /// <returns></returns>
    [HttpPost, Route("ResubscribeScheduleInterview/{id}")]
    public async Task<ServiceResult> ResubscribeScheduleInterview(long id, [FromBody] ResumeRescheduleInterviewForm1 input)
    {
        return await _service.RescheduleInterview(id, new ResumeRescheduleInterviewForm { InterviewStaffs = input.InterviewStaffs }, "ResubscribeSchedule");
    }
    #endregion

    #region 面试评估（主管填写）
    /// <summary>
    /// 面试评估（主管填写）
    /// </summary> 
    /// <param name="id">简历Id</param>
    /// <param name="input">input</param>
    /// <param name="status">状态，0:暂存;1:提交</param>
    /// <param name="source">input</param>
    /// <returns></returns>
    [HttpPost, Route("AssessInterview/{id}/{status}/{source}")]
    public async Task<ServiceResult> AssessInterview(long id, int status, [FromBody] List<Dictionary<string, object>> input, string source)
    {
        return await _service.AssessInterview(id, status, input, source);
    }
    #endregion

    #region 变更面试官
    /// <summary>
    /// 变更面试官
    /// </summary> 
    /// <param name="id">简历Id</param>
    /// <param name="InterviewStaffs">面试官列表</param>
    /// <returns></returns>
    [HttpPost, Route("ModifyInterviewer/{id}")]
    public async Task<ServiceResult> ModifyInterviewer(long id, [FromBody] List<ResumeRecommendFormStaff> InterviewStaffs)
    {
        return await _service.ModifyInterviewer(id, InterviewStaffs);
    }
    #endregion

    #region 转入已发Offer
    /// <summary>
    /// 转入已发Offer
    /// </summary> 
    /// <param name="id">简历Id</param> 
    /// <param name="extFields">扩展栏位</param> 
    /// <param name="templateId">扩展栏位</param> 
    /// <returns></returns>
    [HttpPost, Route("TransferHasSendOffer/{id}/{templateId}")]
    public async Task<ServiceResult> TransferHasSendOffer(long id, long templateId, [FromBody] Dictionary<string, string> extFields)
    {
        return await _service.TransferHasSendOffer(id, templateId, extFields);
    }
    #endregion

    #region 发offer
    /// <summary>
    /// 发offer
    /// </summary> 
    /// <param name="id">简历Id</param> 
    /// <param name="extFields">扩展栏位</param> 
    /// <param name="templateId">扩展栏位</param> 
    /// <returns></returns>
    [HttpPost, Route("SendOffer/{id}/{templateId}")]
    public async Task<ServiceResult> SendOffer(long id, long templateId, [FromBody] Dictionary<string, string> extFields)
    {
        return await _service.SendOffer(id, templateId, extFields);
    }
    #endregion

    #region 已发offer提醒
    /// <summary>
    /// 已发offer提醒
    /// </summary> 
    /// <param name="ids">简历Id,列表</param> 
    /// <returns></returns>
    [HttpPost, Route("RemindHasOffer")]
    public async Task<ServiceResult> RemindHasOffer([FromBody] List<long> ids)
    {
        return await _service.RemindHasOffer(ids);
    }
    #endregion

    #region 已报到/未报道接口
    /// <summary>
    /// 已报到/未报道接口
    /// </summary> 
    /// <param name="ids">简历Id</param> 
    /// <param name="value">已报到传true，未报到传false</param> 
    /// <returns></returns>
    [HttpPost, Route("ModifyIsOffer/{value}")]
    public async Task<ServiceResult> ModifyIsOffer([FromBody] List<long> ids, bool value)
    {
        return await _service.ModifyIsOffer(ids, value);
    }
    #endregion

    #region 不合适
    /// <summary>
    /// 不合适
    /// </summary> 
    /// <param name="input">简历Ids</param> 
    /// <returns></returns>
    [HttpPost, Route("Fail")]
    public async Task<ServiceResult> Fail([FromBody] ResumeFailInterviewForm input) => await _service.Fail(input);
    #endregion

    #region ESS端查询面试记录
    /// <summary>
    /// ESS端查询面试记录
    /// </summary> 
    /// <param name="body">body</param>
    /// <returns></returns> 
    [HttpPost, Route("QueryESS")]
    public async Task<ServicePageResult<Ghrh_ResumeDto>> QueryESS([FromBody] QueryBody body)
    {
        var condition = "1=1";
        return await _service.QueryESS(body, condition);
    }
    #endregion

    #region 获取安排面试表单信息
    /// <summary>
    /// 获取安排面试表单信息
    /// </summary> 
    /// <param name="id">简历ID</param>
    /// <returns></returns> 
    [HttpPost, Route("QueryScheduleInterviewForm/{id}")]
    public async Task<ServiceResult<ResumeScheduleInterviewResult>> QueryScheduleInterviewForm(long id)
    {
        return await _service.QueryScheduleInterviewForm(id);
    }
    #endregion

    #region 取消面试
    /// <summary>
    /// 取消面试
    /// </summary> 
    /// <param name="id">简历ID</param>
    /// <param name="body">body</param>
    /// <returns></returns> 
    [HttpPost, Route("CancelInterview/{id}")]
    public async Task<ServiceResult> CancelInterview(long id, [FromBody] ResumeCancelInterviewForm body)
    {
        return await _service.CancelInterview(id, body);
    }
    #endregion

    #region 转入待发Offer
    /// <summary>
    /// 转入待发Offer
    /// </summary> 
    /// <param name="ids">简历ID</param> 
    /// <returns></returns> 
    [HttpPost, Route("ApplyOfferApproval")]
    public async Task<ServiceResult> ApplyOfferApproval([FromBody] List<long> ids)
    {
        return await _service.ApplyOfferApproval(ids);
    }
    #endregion

    #region 简历下载
    /// <summary>
    /// 简历下载
    /// </summary> 
    /// <param name="ids">简历ID</param> 
    /// <returns></returns> 
    [HttpPost, Route("Download")]
    public async Task<ServiceResult<string>> Download([FromBody] List<long> ids)
    {
        return await _service.Download(ids);
    }
    #endregion

    #region 获取评估信息
    /// <summary>
    /// 获取评估信息
    /// </summary> 
    /// <param name="id">简历ID</param>
    /// <param name="assessForm">assessForm</param>
    /// <returns></returns> 
    [HttpPost, Route("QueryAssessForm/{id}")]
    public async Task<ServiceResult<dynamic>> QueryAssessForm(long id, [FromBody] ResumeAssessForm assessForm) => await _service.QueryAssessForm(id, null, assessForm);

    /// <summary>
    /// 获取评估信息
    /// </summary> 
    /// <param name="id">简历ID</param>
    /// <param name="orderId">面试单ID</param>
    /// <param name="assessForm">assessForm</param>
    /// <returns></returns> 
    [HttpPost, Route("QueryAssessForm/{id}/{orderId}")]
    public async Task<ServiceResult<dynamic>> QueryAssessForm(long id, long orderId, [FromBody] ResumeAssessForm assessForm) => await _service.QueryAssessForm(id, orderId, assessForm);

    #endregion

    #region 获取面试日志
    /// <summary>
    /// 获取面试日志
    /// </summary> 
    /// <param name="id">简历ID</param>
    /// <returns></returns> 
    [HttpPost, Route("Log/{id}")]
    public async Task<ServiceResult<List<ResumeLog>>> Log(long id) => await _service.Log(id);

    #endregion

    #region 获取面试日志
    /// <summary>
    /// 获取面试日志
    /// </summary> 
    /// <param name="id">简历Id</param> 
    /// <param name="extFields">扩展栏位</param> 
    /// <param name="templateId">扩展栏位</param> 
    /// <returns></returns> 
    [HttpPost, Route("OfferDownLoad/{id}/{templateId}")]
    public async Task<ServiceResult<string>> OfferDownLoad(long id, long templateId, [FromBody] Dictionary<string, string> extFields) => await _service.OfferDownLoad(id, templateId, extFields);

    #endregion

    #region 同步数据至人事资料
    [HttpGet, Route("SyncToStaff/{id}"), AllowAnonymous]
    public async Task<bool> SyncToStaff(long id) => await _service.SyncToStaff(id);

    [HttpPost, Route("Shihua_OA")]
    public async Task Shihua_OA_Sync(long id) => await _service.Shihua_OA_Sync();

    #endregion

    #region 招聘工作台初始化接口
    /// <summary>
    /// 招聘工作台初始化接口
    /// </summary> 
    /// <param name="langId">语言别</param>  
    /// <param name="menuName">meuName</param>  
    /// <returns></returns> 
    [HttpPost, Route("QueryWorkStationInit/{langId}")]
    public async Task<ServiceResult<JArray>> QueryWorkstationInit(int langId, string menuName) => await _service.QueryWorkstationInit(langId, menuName);

    #endregion

    #region 招聘工作台招聘统计
    /// <summary>
    /// 招聘工作台招聘统计
    /// </summary> 
    /// <param name="langId">语言别</param>  
    /// <returns></returns> 
    [HttpPost, Route("QueryWorkStationStatisticsChart/{langId}")]
    public async Task<ServiceResult<dynamic>> QueryWorkStationStatisticsChart(int langId) => await _service.QueryWorkStationStatisticsChart(langId);

    #endregion

    #region 录用名单
    [HttpPost, Route("QueryHireList")]
    public async Task<ServicePageResult<Ghrh_ResumeDto>> QueryHireList([FromBody] QueryBody body)
    {
        return await _service.QueryHireList(body);
    }
    #endregion

    #region Excel导出录用名单
    /// <summary>
    /// Excel导出录用名单
    /// </summary>
    /// <param name="body"></param>
    /// <returns></returns>
    [HttpPost, Route("ExportHireExcel")]
    public virtual async Task<ServiceResult<ExcelData>> ExportHireExcel([FromBody] QueryExport body)
    {
        return await _service.ExportHireExcel(body);
    }
    #endregion 
}