use utf8;
package CLMApp::Schema::Result::Market;

# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE

=head1 NAME

CLMApp::Schema::Result::Market

=cut

use strict;
use warnings;

use base 'DBIx::Class::Core';

=head1 COMPONENTS LOADED

=over 4

=item * L<DBIx::Class::InflateColumn::DateTime>

=back

=cut

__PACKAGE__->load_components("InflateColumn::DateTime");

=head1 TABLE: C<Market>

=cut

__PACKAGE__->table("Market");

=head1 ACCESSORS

=head2 marketid

  data_type: 'integer'
  is_auto_increment: 1
  is_nullable: 0

=head2 chaingroupid

  data_type: 'integer'
  default_value: 0
  is_nullable: 1

=head2 customwarehousename

  data_type: 'varchar'
  is_nullable: 1
  size: 256

=head2 customwarehousenumber

  data_type: 'varchar'
  is_nullable: 1
  size: 256

=head2 active

  data_type: 'integer'
  default_value: 1
  is_nullable: 1

=head2 distributorwarehouseid

  data_type: 'integer'
  default_value: 0
  is_nullable: 1

=head2 ordersystem

  data_type: 'integer'
  default_value: 0
  is_nullable: 1

=head2 invoicesystem

  data_type: 'integer'
  default_value: 0
  is_nullable: 1

=head2 distributorid

  data_type: 'integer'
  default_value: 0
  is_nullable: 1

=cut

__PACKAGE__->add_columns(
  "marketid",
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
  "chaingroupid",
  { data_type => "integer", default_value => 0, is_nullable => 1 },
  "customwarehousename",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "customwarehousenumber",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "active",
  { data_type => "integer", default_value => 1, is_nullable => 1 },
  "distributorwarehouseid",
  { data_type => "integer", default_value => 0, is_nullable => 1 },
  "ordersystem",
  { data_type => "integer", default_value => 0, is_nullable => 1 },
  "invoicesystem",
  { data_type => "integer", default_value => 0, is_nullable => 1 },
  "distributorid",
  { data_type => "integer", default_value => 0, is_nullable => 1 },
);

=head1 PRIMARY KEY

=over 4

=item * L</marketid>

=back

=cut

__PACKAGE__->set_primary_key("marketid");


# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-11-12 14:38:17
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:lgWI5w94w5ZW+Bwzvmeyyw

__PACKAGE__->belongs_to(
  "chaingrp",
  "CLMApp::Schema::Result::ChainGroup",
  { "foreign.chaingroupid" => "self.chaingroupid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);

__PACKAGE__->belongs_to(
  "distwhs",
  "CLMApp::Schema::Result::DistributorWarehouse",
  { "foreign.distributorwarehouseid" => "self.distributorwarehouseid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);

__PACKAGE__->belongs_to(
  "ordersystems",
  "CLMApp::Schema::Result::OrderInvoiceSystem",
   sub {
      my $args = shift;

      return {
        "$args->{foreign_alias}.ordersystem" =>  { '=' => 1},
        "$args->{foreign_alias}.id" => { -ident => "$args->{self_alias}.ordersystem" },
        "$args->{foreign_alias}.deleted"   => { '=' => 0 },
      };
    },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'LEFT' },
);

__PACKAGE__->belongs_to(
  "invoicesystems",
  "CLMApp::Schema::Result::OrderInvoiceSystem",
   sub {
      my $args = shift;

      return {
        "$args->{foreign_alias}.invoicesystem" =>  { '=' => 1},
        "$args->{foreign_alias}.id" => { -ident => "$args->{self_alias}.invoicesystem" },
        "$args->{foreign_alias}.deleted"   => { '=' => 0 },
      };
    },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'LEFT' },
);

__PACKAGE__->belongs_to(
  "distributors",
  "CLMApp::Schema::Result::DistributorCompany",
  { "foreign.distributorcompanyid" => "self.distributorid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);

__PACKAGE__->has_many(
  "customersystems",
  "CLMApp::Schema::Result::CustomerSystem",
  { "foreign.marketid" => "self.marketid" },
  { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION", join_type => 'left' },
);


# You can replace this text with custom code or comments, and it will be preserved on regeneration
1;
