package com.ifish.util;

import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Properties;

import com.ifish.enums.SubDirectoryEnum;

/**
 * 文件目录及地址
 *
 * @author Administrator
 *
 */
public class IfishFilePath {
    //头像地址
    public static String path_img;
    /**
     * 图片头地址
     */
    public static String link_img_head;
    //商家图片地址
    public static String path_shops;
    //商品介绍图片
    public static String path_commodity;
    //微信分享页面
    public static String path_share_html;
    //微信分享页图片
    public static String path_share_img;
    //看护报告页面
    public static String path_look_html;
    //看护报告图片
    public static String path_look_img;
    //html名字
    public static String html_name;
    //图片上传格式
    public static String check_style;
    //云信爱鱼奇官方帐号
    public static String ifish_account;
    //IM官方手机号
    public static String netease_phone;
    //直播间封面
    public static String path_room_img;
    //FastDFS商家视频上传URL访问路径(本地和测试环境)
    public static String fastDFS_url_local;
    //FastDFS商家视频上传URL访问路径(正式环境)
    public static String fastDFS_url_app;

    static {
        Properties prop = new Properties();
        InputStream in = IfishFilePath.class.getResourceAsStream("/property.properties");
        try {
            prop.load(in);
            //利用反射机制给属性赋值
            Field[] fields = IfishFilePath.class.getDeclaredFields();
            for (Field field : fields) {
                String name = field.getName();
                field.set(IfishFilePath.class, prop.getProperty(name).trim());
            }
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 验证图片格式
     */
    public static String checkImgName(String fileName) {
        //对格式进行验证
        int index = fileName.lastIndexOf(".");
        String extEndName = fileName.substring(++index, fileName.length());
        if (check_style.indexOf(extEndName.toUpperCase()) == -1) {
            return null;
        }
        //返回格式.png
        return "." + extEndName;
    }

    /**
     * 获取图片链接地址
     *
     * @param type
     * @return
     */
    public static String getPath(SubDirectoryEnum pictureEnum, String fileName) {
        return link_img_head + pictureEnum.getKey() + fileName;
    }

}
