# frozen_string_literal: true module Imis module Panel class Vsc BUSINESS_OBJECT = 'ABC_ASC_Vessel_Safety_Checks' attr_reader :api def initialize(api = nil) @api = api || Api.new end def get(ordinal) api.get(BUSINESS_OBJECT, url_id: "~#{api.imis_id}|#{ordinal}") end def create(data) api.post(BUSINESS_OBJECT, payload(data), url_id: '') end def update(data) api.put(BUSINESS_OBJECT, payload(data), url_id: "~#{api.imis_id}|#{data[:ordinal]}") end def destroy(ordinal) api.delete(BUSINESS_OBJECT, url_id: "~#{api.imis_id}|#{ordinal}") end private # rubocop:disable Metrics/MethodLength def payload(data) { '$type' => 'Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts', 'EntityTypeName' => 'ABC_ASC_Vessel_Safety_Checks', 'PrimaryParentEntityTypeName' => 'Party', 'Identity' => { '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts', 'EntityTypeName' => 'ABC_ASC_Vessel_Safety_Checks', 'IdentityElements' => { '$type' => 'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib]], mscorlib', '$values' => [api.imis_id] } }, 'PrimaryParentIdentity' => { '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts', 'EntityTypeName' => 'Party', 'IdentityElements' => { '$type' => 'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib]], mscorlib', '$values' => [api.imis_id] } }, 'Properties' => { '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts', '$values' => [ { '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts', 'Name' => 'ID', 'Value' => api.imis_id }, ( if data[:ordinal] { '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts', 'Name' => 'Ordinal', 'Value' => { '$type' => 'System.Int32', '$value' => data[:ordinal] } } end ), { '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts', 'Name' => 'Source_System', 'Value' => 'Manual ITCom Entry' }, { '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts', 'Name' => 'ABC_ECertificate', 'Value' => data[:certificate] }, { '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts', 'Name' => 'Activity_Type', 'Value' => 'VSC' }, { '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts', 'Name' => 'Description', 'Value' => 'Vessel Safety Checks' }, { '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts', 'Name' => 'Effective_Date', 'Value' => "#{data[:year]}-12-01T00:00:00" }, { '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts', 'Name' => 'Quantity', 'Value' => { '$type' => 'System.Int32', '$value' => data[:count] } }, { '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts', 'Name' => 'Thru_Date', 'Value' => "#{data[:year]}-12-31T00:00:00" }, { '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts', 'Name' => 'Transaction_Date', 'Value' => Time.now.strftime('%Y-%m-%dT%H:%M:%S') } ].compact } } end # rubocop:enable Metrics/MethodLength end end end