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

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.web.modules.trading.domain.BizMarketDailyQuote;

/**
 * 日度行情展示标签解析。
 */
public final class MarketDailyQuoteLabelResolver
{
    private MarketDailyQuoteLabelResolver()
    {
    }

    public static void enrich(BizMarketDailyQuote row)
    {
        if (row == null)
        {
            return;
        }
        row.setCattleGenderName(cattleGenderName(row.getCattleGender()));
        row.setWeightGradeName(optionalName(row.getWeightGrade(), WEIGHT_NAMES));
        row.setGrowthStageName(optionalName(row.getGrowthStage(), GROWTH_NAMES));
        row.setAgeMonthGradeName(optionalName(row.getAgeMonthGrade(), AGE_NAMES));
        row.setFatGradeName(optionalName(row.getFatGrade(), FAT_NAMES));
        row.setPriceUnitName(priceUnitName(row.getPriceUnit()));
        row.setSupplyStatusName(supplyStatusName(row.getSupplyStatus()));
        List<Integer> factors = ChangeFactorsCodec.parseToList(row.getChangeFactors());
        row.setChangeFactorList(factors);
        List<String> names = new ArrayList<>();
        for (Integer code : factors)
        {
            if (code != null && code >= 1 && code <= CHANGE_FACTOR_NAMES.length)
            {
                names.add(CHANGE_FACTOR_NAMES[code - 1]);
            }
        }
        row.setChangeFactorNames(names);
    }

    private static String cattleGenderName(Integer v)
    {
        if (v == null)
        {
            return "";
        }
        switch (v)
        {
            case MarketDailyQuoteRules.CATTLE_GENDER_BULL:
                return "公牛";
            case MarketDailyQuoteRules.CATTLE_GENDER_COW:
                return "母牛";
            case MarketDailyQuoteRules.CATTLE_GENDER_MIXED:
                return "公母混合";
            default:
                return "";
        }
    }

    private static String priceUnitName(Integer v)
    {
        if (v == null)
        {
            return "";
        }
        return v == MarketDailyQuoteRules.PRICE_UNIT_PER_HEAD ? "元/头" : "元/斤";
    }

    private static String supplyStatusName(Integer v)
    {
        if (v == null)
        {
            return "";
        }
        switch (v)
        {
            case 1:
                return "货源充足";
            case 2:
                return "货源减少";
            case 3:
                return "货源增多";
            default:
                return "";
        }
    }

    private static String optionalName(Integer v, String[] names)
    {
        if (v == null || v < 1 || v > names.length)
        {
            return "";
        }
        return names[v - 1];
    }

    private static final String[] WEIGHT_NAMES = {
            "50斤以下", "50-100斤", "100-200斤", "200-300斤", "300-500斤", "500-800斤", "800斤以上"
    };

    private static final String[] GROWTH_NAMES = { "犊牛", "架子牛", "屠宰牛" };

    private static final String[] AGE_NAMES = {
            "1月龄", "2-3月龄", "4-5月龄", "6-7月龄", "8-9月龄", "10-11月龄", "12月龄"
    };

    private static final String[] FAT_NAMES = { "43%", "45%", "50%", "53%" };

    private static final String[] CHANGE_FACTOR_NAMES = {
            "天气", "节日", "政策", "供大于求", "供不应求", "其他产地冲击", "产地抬价", "其他"
    };
}
