package org.example.seed.domain;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.example.seed.catalog.ChefStatus;
import org.example.seed.constraint.Curp;
import org.example.seed.constraint.Rfc;
import org.example.seed.group.chef.ChefCreateGroup;
import org.example.seed.group.chef.ChefRegisterGroup;
import org.example.seed.group.chef.ChefUpdateGroup;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;
import java.util.UUID;

/**
 * Created by PINA on 26/06/2017.
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class Chef extends Dates {

  @NotNull(groups = {ChefRegisterGroup.class, ChefUpdateGroup.class})
  @Size(min = 36, max = 36, groups = {ChefRegisterGroup.class, ChefUpdateGroup.class})
  private String id;

  @Null(groups = {ChefCreateGroup.class})
  @Rfc(groups = {ChefRegisterGroup.class, ChefUpdateGroup.class})
  @NotNull(groups = {ChefRegisterGroup.class, ChefUpdateGroup.class})
  @Size(min = 13, max = 13, groups = {ChefRegisterGroup.class, ChefUpdateGroup.class})
  private String rfc;

  @Null(groups = {ChefCreateGroup.class})
  @Curp(groups = {ChefRegisterGroup.class, ChefUpdateGroup.class})
  @NotNull(groups = {ChefRegisterGroup.class, ChefUpdateGroup.class})
  @Size(min = 18, max = 18, groups = {ChefRegisterGroup.class, ChefUpdateGroup.class})
  private String curp;

  @NotNull(groups = {ChefUpdateGroup.class})
  @Size(min = 2, max = 2, groups = {ChefUpdateGroup.class})
  @Null(groups = {ChefCreateGroup.class, ChefRegisterGroup.class})
  private String country;

  @Null(groups = {ChefCreateGroup.class, ChefRegisterGroup.class})
  @Min(value = 0, groups = {ChefCreateGroup.class, ChefRegisterGroup.class, ChefUpdateGroup.class})
  @Max(value = 5, groups = {ChefCreateGroup.class, ChefRegisterGroup.class, ChefUpdateGroup.class})
  private Float rating;

  @NotNull(groups = {ChefRegisterGroup.class, ChefUpdateGroup.class})
  private ChefStatus status;

  private boolean active;

  @Valid
  @NotNull(groups = {ChefCreateGroup.class, ChefRegisterGroup.class, ChefUpdateGroup.class})
  private Account account;

  @Valid
  @NotEmpty(groups = {ChefUpdateGroup.class})
  @Null(groups = {ChefCreateGroup.class, ChefRegisterGroup.class})
  private List<Telephone> telephones;

  public Chef() {
    this.id = UUID.randomUUID().toString();
  }
}

@@ -165,16 +165,56 @@
 t.Curp;%0A
+import org.example.seed.constraint.One;%0A
 import o
@@ -2212,23 +2212,19 @@
 lid%0A  @N
-otEmpty
+ull
 (groups 
@@ -2222,35 +2222,35 @@
 l(groups = %7BChef
-Upd
+Cre
 ateGroup.class%7D)
@@ -2245,36 +2245,35 @@
 roup.class%7D)%0A  @
-Null
+One
 (groups = %7BChefC
@@ -2263,38 +2263,40 @@
 e(groups = %7BChef
-Crea
+Regis
 te
+r
 Group.class, Che
@@ -2286,38 +2286,59 @@
 rGroup.class
-, ChefRegis
+%7D)%0A  @NotEmpty(groups = %7BChefUpda
 te
-r
 Group.class%7D

add validation constraint within Chef domain