/**
 * Copyright (c) 2003-2004 System Integrator Corporation.
 *                 All Rights Reserved.
 */
package jp.co.sint.basic;

import jp.co.sint.config.SIConfig;
import jp.co.sint.tools.SIStringUtil;

import org.apache.log4j.Category;

/**
 * @version $Id: SIOrderDetailPK.java,v 1.0 2003/11/20 Exp $
 * @author  Jinwang Chen
* <br>Description:
 * <p>History</p>
 * <p>Author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reason</p>
 *  ============&nbsp;&nbsp;&nbsp;==========&nbsp;&nbsp;===========================<br>
 * Jinwang Chen   2003/11/20 9:52:19  Original
 */
public class SIOrderDetailPK {
  //ログ用のインスタンスの生成
  private static Category log=Category.getInstance(SIConfig.SILOG4J_WEBSHOP_CATEGORY_NAME);

  private String shopCode="";
  private String cmdtyCode="";
  private String individualCode="";
  private String addressCode="";
  private String deliveryTypeName="";
  private String amountNameTxt="";
  private String deliveryTypeNameTxt="";
  private String orderDeliveryCode="";
  private String orderDetailCode="";
  private String stndrdCode1="";
  private String elementCode1="";
  private String stndrdCode2="";
  private String elementCode2="";

  public SIOrderDetailPK(){}

  /**
   * <b>SIOrderDetailPK</b>
   * コンストラクタ
   * 初期値をセットする
   * @param lCartCmdty　　SICartCmdty
   * @param lAddressCode  アドレスコード
   */
  public SIOrderDetailPK(SICartCmdty lCartCmdty,String lAddressCode){
    this(lCartCmdty.getShopCode(),
         lCartCmdty.getCmdtyCode(),
         lCartCmdty.getIndividualCode(),
         lCartCmdty.getStndrdCode1(),
         lCartCmdty.getElementCode1(),
         lCartCmdty.getStndrdCode2(),
         lCartCmdty.getElementCode2(),
         lAddressCode);
  }

  /**
   * <b>SIOrderDetailPK</b>
   * コンストラクタ
   * 初期値をセットする
   * @param lShopCode      ショップコード
   * @param lCmdtyCode　　　商品コード
   * @param lStndrdCode1　　規格コード１
   * @param lElementCode1　エレメントコード１
   * @param lStndrdCode2　　規格コード２
   * @param lElementCode2　エレメントコード２
   */
  public SIOrderDetailPK(String lShopCode,
                         String lCmdtyCode,
                         String lindividualCode,
                         String lStndrdCode1,
                         String lElementCode1,
                         String lStndrdCode2,
                         String lElementCode2){
    this(lShopCode,lCmdtyCode,lindividualCode,lStndrdCode1,lElementCode1,lStndrdCode2,lElementCode2,"");
  }

  /**
   * <b>SIOrderDetailPK</b>
   * コンストラクタ
   * 初期値をセットする
   * @param lShopCode      ショップコード
   * @param lCmdtyCode　　　商品コード
   * @param lStndrdCode1　　規格コード１
   * @param lElementCode1　エレメントコード１
   * @param lStndrdCode2　　規格コード２
   * @param lElementCode2　エレメントコード２
   * @param lAddressCode　　アドレスコード
   */
  public SIOrderDetailPK(String lShopCode,
                         String lCmdtyCode,
                         String lindividualCode,
                         String lStndrdCode1,
                         String lElementCode1,
                         String lStndrdCode2,
                         String lElementCode2,
                         String lAddressCode){
    this.shopCode =lShopCode;
    this.cmdtyCode=lCmdtyCode;
    this.individualCode=lindividualCode;
    this.stndrdCode1=lStndrdCode1;
    this.elementCode1=lElementCode1;
    this.stndrdCode2=lStndrdCode2;
    this.elementCode2=lElementCode2;
    this.addressCode=lAddressCode;
    reSetFieldName();
  }

  /**
   * <b>setFiledNameTxt</b>
   *
   * @param lFieldNameTxt
   */
  public void setFieldNameTxt(String lFieldNameTxt){
    String lSuffixName="";
    String[] lSuffix={"","",""};
    int lStart=0;

    if (lFieldNameTxt.startsWith(SIConfig.SIPREFIX_ORDER_COUNTER_AMOUNT_NAME)){
      lStart=SIConfig.SIPREFIX_ORDER_COUNTER_AMOUNT_NAME.length();
    }else if (lFieldNameTxt.startsWith(SIConfig.SIPREFIX_ORDER_COUNTER_DELIVERY_NAME)){
      lStart=SIConfig.SIPREFIX_ORDER_COUNTER_DELIVERY_NAME.length();
    }else return;

    lSuffixName=lFieldNameTxt.substring(lStart);
    lSuffix=SIStringUtil.split(lSuffixName,SIConfig.SIWEBSHOPPING_TOKEN);
    if (lSuffix.length==8){
      this.shopCode=lSuffix[0];
      this.cmdtyCode=lSuffix[1];
      this.individualCode=lSuffix[2];
      this.stndrdCode1=lSuffix[3];
      this.elementCode1=lSuffix[4];
      this.stndrdCode2=lSuffix[5];
      this.elementCode2=lSuffix[6];
      this.addressCode=lSuffix[7];
    }
    reSetFieldName();
  }
  //EDBTG003-00 elecs-matsushima add start
  /**
   * <b>setFiledNameTxt</b>
   *
   * @param lFieldNameTxt
   */
  public void setFieldNameTxtUpdate(String lFieldNameTxt){
    String lSuffixName="";
    String[] lSuffix={"","",""};
    int lStart=0;

    if (lFieldNameTxt.startsWith(SIConfig.SIPREFIX_ORDER_COUNTER_AMOUNT_NAME)){
      lStart=SIConfig.SIPREFIX_ORDER_COUNTER_AMOUNT_NAME.length();
    }else if (lFieldNameTxt.startsWith(SIConfig.SIPREFIX_ORDER_COUNTER_DELIVERY_NAME)){
      lStart=SIConfig.SIPREFIX_ORDER_COUNTER_DELIVERY_NAME.length();
    }else return;

    lSuffixName=lFieldNameTxt.substring(lStart);
    lSuffix=SIStringUtil.split(lSuffixName,SIConfig.SIWEBSHOPPING_TOKEN);
    if (lSuffix.length==10){
      this.shopCode=lSuffix[0];
      this.cmdtyCode=lSuffix[1];
      this.individualCode=lSuffix[2];
      this.stndrdCode1=lSuffix[3];
      this.elementCode1=lSuffix[4];
      this.stndrdCode2=lSuffix[5];
      this.elementCode2=lSuffix[6];
      this.addressCode=lSuffix[7];
    }
    reSetFieldName();
  }
  //EDBTG003-00 elecs-matsushima add end

  public void setOrderDetailCode(String lOrderDetailCode){
    String[] lSuffix={"","",""};
    lSuffix=SIStringUtil.split(lOrderDetailCode,SIConfig.SIWEBSHOPPING_TOKEN);
    // EDBTG003-00 [不具合管理票-No30] mod start
//    if (lSuffix.length==8){
    if (lSuffix.length==10) {
    // EDBTG003-00 [不具合管理票-No30] mod end
      this.shopCode=lSuffix[0];
      this.cmdtyCode=lSuffix[1];
      this.individualCode=lSuffix[2];
      this.stndrdCode1=lSuffix[3];
      this.elementCode1=lSuffix[4];
      this.stndrdCode2=lSuffix[5];
      this.elementCode2=lSuffix[6];
      this.addressCode=lSuffix[7];
    }
    reSetFieldName();
  }

  //EDBTG003-00 elecs-matsushima add start
  public void setOrderDetailCodeUpdate(String lOrderDetailCode){
    String[] lSuffix={"","",""};
    lSuffix=SIStringUtil.split(lOrderDetailCode,SIConfig.SIWEBSHOPPING_TOKEN);
    if (lSuffix.length==10){
      this.shopCode=lSuffix[0];
      this.cmdtyCode=lSuffix[1];
      this.individualCode=lSuffix[2];
      this.stndrdCode1=lSuffix[3];
      this.elementCode1=lSuffix[4];
      this.stndrdCode2=lSuffix[5];
      this.elementCode2=lSuffix[6];
      this.addressCode=lSuffix[7];
    }
    reSetFieldName();
  }
  //EDBTG003-00 elecs-matsushima add end

  public void setOrderDeliveryCode(String lOrderDeliveryCode){
    String[] lSuffix={"","",""};

    lSuffix=SIStringUtil.split(lOrderDeliveryCode,SIConfig.SIWEBSHOPPING_TOKEN);
    if (lSuffix.length>0)this.addressCode=lSuffix[0];
    if (lSuffix.length>1)this.deliveryTypeName=lSuffix[1];
    if (lSuffix.length>2)this.shopCode=lSuffix[2];
    reSetFieldName();
  }

  public void setShopCode(String lShopCode){
    this.shopCode=lShopCode;
    reSetFieldName();
  }

  public void setCmdtyCode(String lCmdtyCode){
    this.cmdtyCode=lCmdtyCode;
    reSetFieldName();
  }

  public void setAddressCode(String lAddressCode){
    this.addressCode=lAddressCode;
    reSetFieldName();
    this.orderDeliveryCode=this.addressCode+SIConfig.SIWEBSHOPPING_TOKEN+this.deliveryTypeName+SIConfig.SIWEBSHOPPING_TOKEN+this.shopCode;
  }

  public void setDeliveryTypeName(String lDeliveryTypeName){
    this.deliveryTypeName=lDeliveryTypeName;
    this.orderDeliveryCode=this.addressCode+SIConfig.SIWEBSHOPPING_TOKEN+this.deliveryTypeName+SIConfig.SIWEBSHOPPING_TOKEN+this.shopCode;
  }

  public String getShopCode(){
    return this.shopCode;
  }

  public String getCmdtyCode(){
    return this.cmdtyCode;
  }

  public String getAddressCode(){
    return this.addressCode;
  }

  public String getDeliveryTypeNameTxt(){
    return this.deliveryTypeNameTxt;
  }

  public String getAmountNameTxt(){
    return this.amountNameTxt;
  }

  public String getOrderDetailCode(){
    return this.orderDetailCode;
  }

  public String getDeliveryTypeName(){
    return this.deliveryTypeName;
  }

  public String getOrderDeliveryCode(){
    return this.orderDeliveryCode;
  }

  private void reSetFieldName(){
    this.orderDetailCode=this.shopCode +SIConfig.SIWEBSHOPPING_TOKEN+
                         this.cmdtyCode +SIConfig.SIWEBSHOPPING_TOKEN+
                         this.individualCode +SIConfig.SIWEBSHOPPING_TOKEN+
                         this.stndrdCode1+SIConfig.SIWEBSHOPPING_TOKEN+
                         this.elementCode1+SIConfig.SIWEBSHOPPING_TOKEN+
                         this.stndrdCode2+SIConfig.SIWEBSHOPPING_TOKEN+
                         this.elementCode2+SIConfig.SIWEBSHOPPING_TOKEN+
                         this.addressCode;
    this.orderDeliveryCode=this.addressCode +SIConfig.SIWEBSHOPPING_TOKEN+this.deliveryTypeName+SIConfig.SIWEBSHOPPING_TOKEN+this.shopCode;

    this.amountNameTxt=SIConfig.SIPREFIX_ORDER_COUNTER_AMOUNT_NAME+
                       this.shopCode+SIConfig.SIWEBSHOPPING_TOKEN+
                       this.cmdtyCode+SIConfig.SIWEBSHOPPING_TOKEN+
                       this.individualCode +SIConfig.SIWEBSHOPPING_TOKEN+
                       this.stndrdCode1+SIConfig.SIWEBSHOPPING_TOKEN+
                       this.elementCode1+SIConfig.SIWEBSHOPPING_TOKEN+
                       this.stndrdCode2+SIConfig.SIWEBSHOPPING_TOKEN+
                       this.elementCode2+SIConfig.SIWEBSHOPPING_TOKEN+
                       this.addressCode;

    this.deliveryTypeNameTxt=SIConfig.SIPREFIX_ORDER_COUNTER_DELIVERY_NAME+
                            this.shopCode+SIConfig.SIWEBSHOPPING_TOKEN+
                            this.cmdtyCode+SIConfig.SIWEBSHOPPING_TOKEN+
                            this.individualCode +SIConfig.SIWEBSHOPPING_TOKEN+
                            this.stndrdCode1+SIConfig.SIWEBSHOPPING_TOKEN+
                            this.elementCode1+SIConfig.SIWEBSHOPPING_TOKEN+
                            this.stndrdCode2+SIConfig.SIWEBSHOPPING_TOKEN+
                            this.elementCode2+SIConfig.SIWEBSHOPPING_TOKEN+
                            this.addressCode;
  }
}
