package com.ruoyi.web.modules.news.support;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.modules.architecture.domain.BizBreedingStandard;
import com.ruoyi.web.modules.architecture.domain.BizEquipmentWorkStandard;
import com.ruoyi.web.modules.architecture.domain.BizFeedingStandard;
import com.ruoyi.web.modules.architecture.domain.BizGrowthSlaughterStandard;
import com.ruoyi.web.modules.industrypolicy.domain.BizIndustryPolicyPublicity;
import com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyMatter;
import com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyProject;
import com.ruoyi.web.modules.innovation.domain.BizTechProjectGuide;
import com.ruoyi.web.modules.prosperity.domain.BizCommonProsperityProject;

/**
 * 移动端养殖资讯详情：已发布且 type 与源表字段一致时可见。
 */
public final class FarmingNewsDetailSupport
{
    private FarmingNewsDetailSupport()
    {
    }

    public static void assertVisibleBreeding(BizBreedingStandard row, String type)
    {
        if (row == null || !FarmingNewsRules.isPublished(row.getPublishStatus()) || !typeEquals(type, row.getStandardType()))
        {
            throw new ServiceException(FarmingNewsRules.NOT_FOUND_MSG);
        }
    }

    public static void assertVisibleFeeding(BizFeedingStandard row, String type)
    {
        if (row == null || !FarmingNewsRules.isPublished(row.getPublishStatus()) || !typeEquals(type, row.getStandardType()))
        {
            throw new ServiceException(FarmingNewsRules.NOT_FOUND_MSG);
        }
    }

    public static void assertVisibleEquipment(BizEquipmentWorkStandard row, String type)
    {
        if (row == null || !FarmingNewsRules.isPublished(row.getPublishStatus()) || !typeEquals(type, row.getStandardType()))
        {
            throw new ServiceException(FarmingNewsRules.NOT_FOUND_MSG);
        }
    }

    public static void assertVisibleGrowth(BizGrowthSlaughterStandard row, String type)
    {
        if (row == null || !FarmingNewsRules.isPublished(row.getPublishStatus()) || !typeEquals(type, row.getStandardType()))
        {
            throw new ServiceException(FarmingNewsRules.NOT_FOUND_MSG);
        }
    }

    public static void assertVisibleTech(BizTechProjectGuide row, String type)
    {
        if (row == null || !FarmingNewsRules.isPublished(row.getPublishStatus()) || !typeEquals(type, row.getProjectType()))
        {
            throw new ServiceException(FarmingNewsRules.NOT_FOUND_MSG);
        }
    }

    public static void assertVisiblePolicy(BizIndustryPolicyPublicity row)
    {
        if (row == null || !FarmingNewsRules.isPublished(row.getPublishStatus()))
        {
            throw new ServiceException(FarmingNewsRules.NOT_FOUND_MSG);
        }
    }

    public static void assertVisibleSubsidyProject(BizSubsidyProject row)
    {
        if (row == null || !FarmingNewsRules.isPublished(row.getPublishStatus()))
        {
            throw new ServiceException(FarmingNewsRules.NOT_FOUND_MSG);
        }
    }

    public static void assertVisibleSubsidyMatter(BizSubsidyMatter row)
    {
        if (row == null || !FarmingNewsRules.isPublished(row.getPublishStatus()))
        {
            throw new ServiceException(FarmingNewsRules.NOT_FOUND_MSG);
        }
    }

    public static void assertVisibleProsperity(BizCommonProsperityProject row)
    {
        if (row == null || !FarmingNewsRules.isPublished(row.getPublishStatus()))
        {
            throw new ServiceException(FarmingNewsRules.NOT_FOUND_MSG);
        }
    }

    private static boolean typeEquals(String expected, String actual)
    {
        return expected != null && expected.equals(StringUtils.trim(actual));
    }
}
