#  Copyright (c) 1997-2021
#  Ewgenij Gawrilow, Michael Joswig, and the polymake team
#  Technische Universität Berlin, Germany
#  https://polymake.org
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------

object NormalToricVariety {

   # @category Producing a normal toric variety
   # Produce a toric variety from a rational Cone.
   # @param Cone<Rational> cone Cone
   # @return NormalToricVariety
   method construct(Cone<Rational>) {
      my $cone = $_[1];
      return new NormalToricVariety(check_fan_objects($cone));
   }

   # @category Producing a normal toric variety
   # Produce a toric variety from a rational fan.
   # @param PolyhedralFan<Rational> fan Fan
   # @return NormalToricVariety
   method construct(PolyhedralFan<Rational>) {
      &Core::BigObject::new_copy;
   }

   rule AFFINE : N_MAXIMAL_CONES{
      $this->AFFINE = ($this->N_MAXIMAL_CONES == 1);
   }

   rule DEGENERATE : LINEALITY_DIM {
      $this->DEGENERATE = $this->LINEALITY_DIM > 0;
   }
   weight 0.1;

   # the number of maximal torus orbits
   # they correspond to the rays of the fan
   rule N_MAXIMAL_TORUS_ORBITS = N_RAYS;

   rule ORBIFOLD = SIMPLICIAL;

   rule FANO : N_MAXIMAL_TORUS_ORBITS, RAYS, MAXIMAL_CONES, DUAL_GRAPH.ADJACENCY {
      # RAYS, MAXIMAL_CONES, DUAL_GRAPH.ADJACENCY are needed to compute ampleness.
    	my $AK = $this->DIVISOR(COEFFICIENTS=>ones_vector($this->N_MAXIMAL_TORUS_ORBITS), temporary);
    	$this->FANO = $AK->AMPLE;
	}
	
}


# @category Producing a normal toric variety
# Creates a toric variety from the normal fan of a polytope and adds the defining divisor of the polytope
# @param Polytope<Rational> P : the input polytope
# @param String name : a name for the divisor
# @return NormalToricVariety
user_function polarized_toric_variety(Polytope<Rational>,$) {
  my $self=shift;
  my $name=shift;
  my $t=new NormalToricVariety(normal_fan($self));
  my $tdiv = new TDivisor("$name",COEFFICIENTS=>primitive($self->FACETS)->col(0));
  $t->add("DIVISOR",$tdiv);
  return $t;
}


# Local Variables:
# mode: perl
# cperl-indent-level: 3
# indent-tabs-mode:nil
# End:
