/*
 Flash: Flashcard program
 Copyright (C) 2005, Niko Matsakis (niko@alum.mit.edu)
 
 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
 of the License, or (at your option) any later version.
 
 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.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#import "ImportParameter.h"
#import "Errors.h"

@implementation ImportParameter

- init
{
    if ((self = [super init])) {
        _column1 = [NSNumber numberWithInt:1];
        _column2 = [NSNumber numberWithInt:2];
    }
    return self;
}

- (NSManagedObject *)language1
{
    return _language1;
}

- (NSNumber *)column1
{
    return _column1;
}

- (NSManagedObject *)relationship
{
    return _relationship;
}

- (NSManagedObject *)language2
{
    return _language2;
}

- (NSNumber *)column2
{
    return _column2;
}

- (BOOL) validateLanguage:(NSManagedObject **)value error: (NSError**)outError
{
    if (*value == nil) {
        *outError = [NSError errorWithDomain:FLASHDOMAIN
                                        code:INVALIDLANG
                                    userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
                                        @"Language must not be nil.", NSLocalizedDescriptionKey, 
                                        nil]];
        return NO;        
    }
    
    return YES;    
}

- (BOOL) validateColumn: (NSNumber **)colValue error: (NSError**)outError
{
    if ([*colValue intValue] <= 0) {
        *outError = [NSError errorWithDomain:FLASHDOMAIN
                                        code:INVALIDCOLUMN
                                    userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
                                        @"Column must be at least 1.", NSLocalizedDescriptionKey, 
                                        nil]];
        return NO;        
    }
    
    return YES;
}

@end
