﻿<cf:project defaultProducerProductionFlags="RemoveDates" 
            xmlns:cf="http://www.softfluent.com/codefluent/2005/1" 
            xmlns:cfpc="http://www.softfluent.com/codefluent/producers.cache/2005/1"
            defaultNamespace="SoftFluent.CarRental" persistencePropertyNameFormat="{1}" 
            defaultKeyPropertyTypeName="int"
            >

  <Customer categoryPath="Customer">
    <Id />
    <EmailAddress collectionKey="true" />
    <Password />
    <FirstName />
    <LastName />
    <FullName persistent="false" onGetEvent="" set="false" />
    <BirthdayDate />
    <LoyaltyProgramMember typeName="bool" />
    <LicenseNo unique="true" />
    <HasPreAccidents typeName="bool" />
    <Age typeName="int" onGetEvent="" persistent="false" />
    <Address typeName="Address" />
    <Rentals typeName="RentalAgreementCollection" includeInSerialization="true" />
    <PaymentType typeName="PayType" usePersistenceDefaultValue="false" />
    <cf:method name="CheckCredentials" body="loadone(EmailAddress, Password) where EmailAddress = @EmailAddress And Password = @Password">
      <cf:parameter name="Password" nullable="false" />
    </cf:method>
    <cf:method name="LoadByWhashingtonState" body="loadone(Address) where Address.City.State.Name Like 'Whashington'" />
    <cf:snippet language="CSharp">
      private void OnGetFullName()
      {
      _fullName = FirstName + " " + LastName;
      }

      private void OnGetAge()
      {
      System.DateTime now = System.DateTime.Now;
      System.TimeSpan age = now.Subtract(BirthdayDate);
      _age = age.Days / 365;
      }
    </cf:snippet>
  </Customer>

  <Address setType="List" persistentName="add_Address" categoryPath="Customer">
    <Id />
    <Line1 typeName="string" />
    <Line2 />
    <City typeName="City" />
    <Zip />
    <Country />
    <Customer typeName="Customer">
      <cf:renderer name="CustomerRenderer" />
    </Customer>
    <cf:view name="MyView">
      <Line1 />
      <City>
        <cf:message cultureName="fr-FR">Ville</cf:message>
        <cf:message cultureName="en-US">City</cf:message>
      </City>
      <Zip>
        <cf:message cultureName="fr-FR">Code Postal</cf:message>
        <cf:message cultureName="en-US">Zip code</cf:message>
      </Zip>
      <State expression="City.State.Name" />
      <Country />
    </cf:view>
  </Address>

  <Car categoryPath="Vehicule">
    <Id />
    <MinDays typeName="int" />
    <VehicleType />
    <VehicleStatus typeName="VehicleStatus" usePersistenceDefaultValue="false" onAfterSetEvent="" />
    <CarPicture typeName="image" />
    <CarDocument typeName="document" />
    <CarVideo typeName="video" sortable="false" />
    <CarGroup typeName="CarGroup" />
    <Repairs typeName="CarRepairCollection" />
    <Rentals typeName="RentalAgreementCollection" />
    <SerialNumber unique="true" onBeforeSetEvent="" typeName="int" />
    <cf:message cultureName="en-US">Car</cf:message>
    <cf:message cultureName="fr-FR">Voiture</cf:message>
    <cf:snippet language="CSharp">
      private void OnAfterSetVehicleStatus(VehicleStatus vehicleStatus)
      {
      //Send for example a mail notifying that vehicule status has been changed
      //Or launch a workflow
      }

      private bool OnBeforeSetSerialNumber(int serialNumber)
      {
      //Trace in database for example access to the SerialNumber by the current user

      return true;
      }
    </cf:snippet>
    <cf:view name="NameOnly">
      <VehicleType />
      <VehicleStatus />
      <MinDays />
      <CategoryName expression="CarGroup.Name" />
    </cf:view>
  </Car>

  <Truck baseTypeName="Car" categoryPath="Vehicule">
    <Weight typeName="float" />
    <Image typeName="image" />
  </Truck>

  <CarRepair categoryPath="Vehicule">
    <Id />
    <Car typeName="Car" />
    <RepairDate typeName="datetime" />
    <Description />
  </CarRepair>

  <RentalAgreement categoryPath="Vehicule">
    <Id />
    <Customer typeName="Customer" />
    <Car typeName="Car" />
    <CarOptions typeName="CarOptions" usePersistenceDefaultValue="false" />
    <PickupBranch typeName="Branch" relationPropertyName="PickedUpRentals" />
    <ActualReturnBranch typeName="Branch" relationPropertyName="ReturnedRentals" />
    <ScheduledReturnBranch typeName="Branch" relationPropertyName="ScheduledRentals" />
    <PickupDate typeName="datetime" />
    <ScheduledReturnDate typeName="datetime" />
    <ActualReturnDate typeName="datetime" />
    <RequestedCarGroup typeName="CarGroup" />
    <ActualCarGroup typeName="CarGroup" />
    <RentalAmount typeName="float" />
    <IsAccepted typeName="bool" />
    <IsAssigned typeName="bool" default="false" />
    <Offers typeName="OfferCollection" relationPropertyName="Rentals" />
    <Coverages typeName="CoverageCollection" />
    <CoverageSubtotalPrice typeName="float" />
    <TotalPrice typeName="float" />
    <CarGroup typeName="CarGroup" onGetEvent="" />
    <ReturnedDate typeName="datetime" onGetEvent="" />
    <Duration typeName="int" onGetEvent="" />
    <cf:method name="LoadByReturnDate" body="load(ActualReturnDate) where ActualReturnDate = @ActualReturnDate" />
    <cf:method name="LoadByPickupDateAndUser" body="load(PickupDate, string firstName) where PickupDate = @PickupDate and Customer.FirstName = @firstName order by Car.CarGroup.Name">
      <cf:message cultureName="en-US">Load by pickup date and first name</cf:message>
      <cf:message cultureName="fr-FR">Charger par date de prise en charge et prénom</cf:message>
    </cf:method>
    <cf:snippet language="CSharp">
      private void OnGetCarGroup()
      {
      _carGroup = ((ActualCarGroup != null)?ActualCarGroup:RequestedCarGroup);
      }

      private void OnGetReturnedDate()
      {
      _returnedDate = ((ActualReturnDate != System.DateTime.MinValue)?ActualReturnDate:ScheduledReturnDate);
      }

      private void OnGetDuration()
      {
      _duration = (ReturnedDate - PickupDate).Days;
      }
    </cf:snippet>
    <cf:method name="AgeCheck" typeName="CodeFluent.Runtime.Rules.ILog.Method, CodeFluent.Runtime.Rules.ILog" returnTypeName="int" body="rule(Customer)">
      <cf:setting name="RuleSetTypeName" value="CarRentalBizProj, CarRentalBizProj" />
    </cf:method>
    
  </RentalAgreement>

  <Offer categoryPath="Vehicule">
    <Id />
    <Name></Name>
    <CarGroupUpgrade typeName="CarGroup" />
    <Rentals typeName="RentalAgreementCollection" relationPropertyName="Offers" />
    <Discount typeName="float" />
  </Offer>

  <Branch categoryPath="Vehicule">
    <Id />
    <Name collectionKey="true" />
    <Line1 />
    <Line2 />
    <Zip />
    <City typeName="City" />
    <PickedUpRentals typeName="RentalAgreementCollection" relationPropertyName="PickupBranch" />
    <ReturnedRentals typeName="RentalAgreementCollection" relationPropertyName="ActualReturnBranch" />
    <ScheduledRentals typeName="RentalAgreementCollection" relationPropertyName="ScheduledReturnBranch" />
  </Branch>

  <Inventory categoryPath="Vehicule">
    <Id />
    <InventoryDate typeName="datetime" />
    <ContactFullName />
    <ContactEmail />
    <InventoryDetails typeName="InventoryDetailCollection" />
    <cf:method name="LoadByDate" body="load(InventoryDate) where InventoryDate = @InventoryDate" />
  </Inventory>

  <InventoryDetail setType="List" categoryPath="Vehicule">
    <CarGroup key="true" typeName="CarGroup" />
    <Branch key="true" typeName="Branch" />
    <Inventory key="true" typeName="Inventory" />
    <CarCount typeName="int" />
  </InventoryDetail>

  <CarGroup categoryPath="Vehicule">
    <Id />
    <Name collectionKey="true" />
    <Category />
    <WeeklyRate typeName="decimal" />
    <DailyRate typeName="decimal" />
    <Upgrades typeName="GroupUpgradeCollection" />
    <Cars typeName="CarCollection" />
  </CarGroup>

  <GroupUpgrade categoryPath="Vehicule">
    <Id />
    <CarGroup typeName="CarGroup" />
    <Priority typeName="int" />
  </GroupUpgrade>

  <Coverage categoryPath="Vehicule">
    <Id />
    <Code />
    <Name />
  </Coverage>

  <State categoryPath="Referential">
    <Id />
    <Name collectionKey="true" />
    <Cities typeName="CityCollection" />
  </State>

  <City categoryPath="Referential">
    <Id />
    <State typeName="State" />
    <Name collectionKey="true" />
    <Branches typeName="BranchCollection" />
    <cfpc:cache typeName="CodeFluent.Runtime.Caching.SimpleCacheManager, CodeFluent.Runtime" enabled="true" />
  </City>

  <PayTypeEnum>
    <Cash />
    <CreditCard />
    <Check />
  </PayTypeEnum>

  <CarOptionsEnum flags="true">
    <GPS />
    <CD />
    <BabySeat />
  </CarOptionsEnum>

  <VehicleStatusEnum>
    <Available default="true">
      <cf:message cultureName="fr-FR">Disponible</cf:message>
      <cf:message cultureName="en-US">Available</cf:message>
    </Available>
    <Rented>
      <cf:message cultureName="fr-FR">Louée</cf:message>
      <cf:message cultureName="en-US">Rented</cf:message>
    </Rented>
    <Reparation>
      <cf:message cultureName="fr-FR">En réparation</cf:message>
      <cf:message cultureName="en-US">Being repaired</cf:message>
    </Reparation>
    <Broken>
      <cf:message cultureName="fr-FR">Endommagée</cf:message>
      <cf:message cultureName="en-US">Broken</cf:message>
    </Broken>
    <Service>
      <cf:message cultureName="fr-FR">En révision</cf:message>
      <cf:message cultureName="en-US">In service</cf:message>
    </Service>
  </VehicleStatusEnum>

  <cf:message name="USER_NOT_FOUND" cultureName="fr-FR">Utilisateur(trice) inconnu(e).</cf:message>
  <cf:message name="USER_NOT_FOUND" cultureName="en-US">User unknown.</cf:message>


</cf:project>