package Bio::ConnectDots::ConnectorQuery::Operator::CsMixin;
use strict;

# generate where clauses for Term assumed to refer to this object
# return (ARRAY of where clauses, ct_sql_alias (undef here), cs_sql_alias)
sub term_where {
  my($self,$term)=@_;
  my $where=[];
  my $name=$self->name;
  my $cs_alias=$term->cs_alias;
  my $cs=$cs_alias->target_object;
  my $cs_id=$cs->db_id;
  my $i=$self->alias_counter;

  my $cs_sql_alias=$cs_alias->name.'_'.$$i_ref++;
  $self->sql_alias2table->{$cs_sql_alias}=$cs->name;

  push(@$where,"$cs_sql_alias.connectorset_id=$cs_id");
  # if $label_ids is empty, the label was '*' -- matches all ids
  my $label_ids=$term->label_ids;
  if (@$label_ids==1) {
    push(@$where,"$cs_sql_alias.label_id=".$label_ids->[0]);
  } elsif (@$label_ids>1) {
    push(@$where,"$cs_sql_alias.label_id IN (".join(',',@$label_ids).")");
  }
  $self->alias_counter($i);
  wantarray? ($where,$cs_sql_alias): $where;
}

1;
