<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
        "http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap namespace="model">

    <typeAlias alias="Manufacturer" type="data.domains.Manufacturer" />
    <typeAlias alias="Model" type="data.domains.Model" />

    <resultMap id="ManufacturerLazymap" class="Manufacturer">
        <result property="manufacturerId" column="id" nullValue="0"/>
        <result property="name" column="name" />
        <result property="models"  column="id" select="model.selectModelsByManufacturerId" />
    </resultMap>


    <resultMap id="ModelLazyMap" class="Model">
        <result property="modelId" column="id" nullValue="0" />
        <result property="name" column="name" />
        <result property="deviceType" column="device_type_id" />
        <result property="manufacturerId" column="manufacturer_id" nullValue="0" />
    </resultMap>

    <select id="selectModelsByManufacturerId" parameterClass="long" resultMap="model.ModelLazyMap">
        SELECT * from model where manufacturer_id=#manufacturerId#
    </select>

    <select id="getAllDeviceModels" resultMap="model.ModelLazyMap">
        Select * from model
    </select>

    <select id="getAllManufacturers" resultMap="model.ManufacturerLazymap">
        Select * from manufacturer
    </select>

    <select id="getModelsByType"  parameterClass="long" resultMap="model.ModelLazyMap">
        Select * from model
              where device_type_id=#typeId#
    </select>

    <select id="getManufacturerNameById" parameterClass="long" resultClass="String">
        Select name from manufacturer where id=#manufacturerId#
    </select>
    
    <select id="getManufacturerById" parameterClass="long" resultMap="model.ManufacturerLazymap">
        Select * from manufacturer where id=#manufacturerId#
    </select>

    <select id="getModelByModelName" parameterClass="string" resultMap="model.ModelLazyMap">
        Select * from model where name=#modelName#
    </select>

    <select id="getModelIdBySerial" parameterClass="String" resultClass="long">
        Select model_id from device where serial_number=#serialNumber#
    </select>

    <insert id="insertModel" parameterClass="Model">
        INSERT  INTO  model (name,device_type_id,manufacturer_id)
                VALUES (#name#,#deviceType#,#manufacturerId#)
           <selectKey resultClass="long">
                SELECT LAST_INSERT_ID() AS ID
           </selectKey>
    </insert>

    <insert id="insertParams" parameterClass="long">
        INSERT INTO parameter(name,visual_name,writable,isdefparam,isvisible_for_admin,model_id,param_type,default_value)
             VALUES ("InternetGatewayDevice.DeviceInfo.SpecVersion","SpecVersion",0,1,1,#modelId#,"string",""),
                    ("InternetGatewayDevice.DeviceInfo.HardwareVersion","HardVersion",0,1,1,#modelId#,"string",""),
                    ("InternetGatewayDevice.DeviceInfo.SoftwareVersion","SoftVersion",0,1,1,#modelId#,"string",""),
                    ("InternetGatewayDevice.ManagementServer.ConnectionRequestURL","Connection URL",0,1,1,#modelId#,"string",""),
                    ("InternetGatewayDevice.ManagementServer.ConnectionRequestPassword","Password",1,1,1,#modelId#,"string",""),
                    ("InternetGatewayDevice.ManagementServer.ConnectionRequestUsername","Username",1,1,1,#modelId#,"string",""),
                    ("InternetGatewayDevice.ManagementServer.PeriodicInformInterval","Interval",1,1,1,#modelId#,"unsignedInt",10),
                    ("InternetGatewayDevice.ManagementServer.PeriodicInformTime","Periodic Time",0,1,1,#modelId#,"string",""),
                    ("InternetGatewayDevice.ManagementServer.URL","Management Server URL",1,1,1,#modelId#,"string","192.168.1.53:30006"),
                    ("InternetGatewayDevice.ManagementServer.Username","Management Server Username",1,1,1,#modelId#,"string",""),
                    ("InternetGatewayDevice.DeviceInfo.ModelName","ModelName",0,1,1,#modelId#,"string","")

    </insert>

    <insert id="insertParams1" parameterClass="long">
        INSERT INTO parameter(name,visual_name,writable,isdefparam,isvisible_for_admin,model_id,param_type,is_lan,default_value)
             VALUES ("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.WEPKey.2.WEPKey","WEPKey.2.WEPKey",0,1,1,#modelId#,"string",1,""),
                    ("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.WEPKey.1.WEPKey","WEPKey.1.WEPKey",0,1,1,#modelId#,"string",1,""),
                    ("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.IEEE11iAuthenticationMode","IEEE11iAuthenticationMode",0,1,1,#modelId#,"string",1,""),
                    ("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.IEEE11iEncryptionModes","IEEE11iEncryptionModes",0,1,1,#modelId#,"string",1,""),
                    ("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.WPAEncryptionModes","WPAEncryptionModes",0,1,1,#modelId#,"string",1,""),
                    ("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.SSID","WLANConfiguration 1 SSID",1,1,1,#modelId#,"string",1,""),
                    ("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.AutoChannelEnable","AutoChannelEnable",1,1,1,#modelId#,"boolean",1,0),
                    ("InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.4.Name","LANEthernetInterfaceConfig",0,1,1,#modelId#,"string",1,"")

    </insert>

     <insert id="insertParams2" parameterClass="long">
        INSERT INTO parameter(name,visual_name,writable,isdefparam,isvisible_for_admin,model_id,param_type,is_lan,default_value)
             VALUES ("InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.DHCPServerEnable","LANHostConfigManagement DHCPServerEnable",1,1,1,#modelId#,"boolean",1,0),
                    ("InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.DomainName","LANHostConfigManagement DomainName",1,1,1,#modelId#,"string",1,""),
                    ("InternetGatewayDevice.LANDevice.1.LANUSBInterfaceConfig.1.Enable","LANUSBInterfaceConfig 1 Enable",1,1,1,#modelId#,"boolean",1,1),
                    ("InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.1.Status","LANEthernetInterfaceConfig 1 Status",0,1,1,#modelId#,"string",1,""),
                    ("InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.1.MACAddress","MACAddress",0,1,1,#modelId#,"string",1,"")

    </insert>



</sqlMap>