package org.ts.ddcs.DataItemTemplate.DataItemTemplateSzy2012;

import org.ts.ddcs.DataItemTemplate.DataItemTemplate;
import org.ts.ddcs.Entity.WqRiverEntity;
import org.ts.ddcs.Tool.BytesHelp;
import org.ts.ddcs.Tool.StringUtil;

/**
 * AFN C0   C 02
 * 自报 水位参数
 */
@SuppressWarnings("all")
public class DataItemTemplateC0_WaterHigh extends DataItemTemplate {

    @Override
    public byte[] Stream(byte[] data) {
        byte[] remain = data;
        if (remain.length < 4) {
            return remain;
        }
        int count = 0;
        this.valueBuff = BytesHelp.subBytes(data, 0, 4);
        count += 4;
        byte tmp = this.valueBuff[0];
        this.valueBuff[0] = this.valueBuff[3];
        this.valueBuff[3] = tmp;
        tmp = this.valueBuff[1];
        this.valueBuff[1] = this.valueBuff[2];
        this.valueBuff[2] = tmp;
        String value = BytesHelp.byte2HexStr(this.valueBuff);
        if (value.equals("FFFFFFFF")) {
            this.varcharValue = "FFFFFFFF";
        } else {
            String flag = value.substring(0, 1);
            String v1 = value.substring(1, 2);
            String v2 = value.substring(2, 3);
            String v3 = value.substring(3, 4);
            String v4 = value.substring(4, 5);
            String v5 = value.substring(5, 6);
            String v6 = value.substring(6, 7);
            String v7 = value.substring(7, 8);
            value = "";
            if (flag.equals("F")) {
                value += "-";
            }
            value += StringUtil.getPrettyNumber(v1 + v2 + v3 + v4 + "." + v5 + v6 + v7);
            this.varcharValue = value;
        }
        if (remain.length - count > 0) {
            remain = BytesHelp.subBytes(remain, count, remain.length - count);
        } else {
            remain = new byte[0];
        }
        this.macth = true;
        return remain;
    }

    @Override
    public void SetEntity(Object entity) {
        WqRiverEntity wqRiverEntity = (WqRiverEntity) entity;
        wqRiverEntity.setHIGH(this.varcharValue);
    }

    @Override
    public boolean OutlierData() {
        if (null != this.valueBuff && this.valueBuff.length > 0) {
            String hexValue = BytesHelp.byte2HexStr(this.valueBuff);
            if (hexValue.equals("FFFFFFFF")) {
                return true;
            }
        }
        return false;
    }
}
